[RESOLVED] Enter Text1 to Text 3 in MsFlexgrid vb6
Hello,
I need your help.
In my vb6 Form1, I have 3 Text boxes and a MsFlexgrid1.
Now what I want to do his, when I click on a vb6 button, it will add the text from Text1 to the first column of the MsFlexgrid1, the text2 to the second column and the Text3 to the column 3.
After, each time that I click on that button, it will add a line with the text from the 3 Text boxes.
I can I do that please?
Thanks for your help.
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
Here you go:
Code:
MsFlexGrid1.AddItem Text1.Text & vbTab & Text2.Text & vbTab & Text3.Text
The Tab character (which vbTab contains) is used to separate the columns
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
Yes, it works.
Just a small problem.
How to auto adjust Msflexgrid column1 width depending on the text in Text1?
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
This is one way to do it... Create a new project and place a commanbutton and a MsFlexgrid... Once you understand the concept, you can apply this to your project...
vb Code:
Private Sub Form_Load()
'~~> Declare variables.
Dim Entry As String, i As Long
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.FixedRows = 0
MSFlexGrid1.Cols = 1
'~~> To add 10 items
For i = 1 To 10
Entry = "This is item number : " & i
MSFlexGrid1.AddItem Entry
Next i
End Sub
Private Sub Command1_Click()
Dim i As Long, maxTwips As Integer, Twips As Integer
With Me.MSFlexGrid1
Me.ScaleMode = vbTwips
'~~> Loop thru items in the row and find textwidth
For i = 0 To .Rows - 1
Twips = Me.TextWidth(.TextMatrix(i, .ColSel))
If Twips > maxTwips Then
maxTwips = Twips
End If
Next i
'~~> Reset Width
.ColWidth(.ColSel) = maxTwips * Me.MSFlexGrid1.Font.Size _
/ Me.Font.Size + 100
End With
End Sub
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
That is valid under the right circumstances, but is not ideal - it only works if the Font for the form and grid are the same (different fonts have different character widths for the same .Size), and it alters the ScaleMode which may cause problems elsewhere.
The "FlexGrid: AutoSize columns" link in my signature contains code which deals with those issues, and allows you to specify other options (such as whether to include the header rows, etc).
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
Thanks, I will do the test and I'll be back in no time for the verdict.
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
This his perfect.
Thanks a lot.
Re: Enter Text1 to Text 3 in MsFlexgrid vb6
No problem. :)
As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).