Results 1 to 8 of 8

Thread: [RESOLVED] Enter Text1 to Text 3 in MsFlexgrid vb6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    28

    Resolved [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.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    28

    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?

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. Private Sub Form_Load()
    2.    '~~> Declare variables.
    3.    Dim Entry As String, i As Long
    4.    
    5.    MSFlexGrid1.FixedCols = 0
    6.    MSFlexGrid1.FixedRows = 0
    7.    
    8.    MSFlexGrid1.Cols = 1
    9.    '~~> To add 10 items
    10.    For i = 1 To 10
    11.       Entry = "This is item number : " & i
    12.       MSFlexGrid1.AddItem Entry
    13.    Next i
    14. End Sub
    15. Private Sub Command1_Click()
    16.     Dim i As Long, maxTwips As Integer, Twips As Integer
    17.     With Me.MSFlexGrid1
    18.         Me.ScaleMode = vbTwips
    19.         '~~> Loop thru items in the row and find textwidth
    20.         For i = 0 To .Rows - 1
    21.             Twips = Me.TextWidth(.TextMatrix(i, .ColSel))
    22.             If Twips > maxTwips Then
    23.                 maxTwips = Twips
    24.             End If
    25.         Next i
    26.         '~~> Reset Width
    27.         .ColWidth(.ColSel) = maxTwips * Me.MSFlexGrid1.Font.Size _
    28.         / Me.Font.Size + 100
    29.     End With
    30. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    28

    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    28

    Re: Enter Text1 to Text 3 in MsFlexgrid vb6

    This his perfect.

    Thanks a lot.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width