Results 1 to 9 of 9

Thread: Button Captions from Flexgrid

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Button Captions from Flexgrid

    Hi All

    I am really struggeling with something simple, i have a vsflexgrid with 1 col and 10 rows i then have an array of 10 command buttons cmdDep and i just can't seem to figure out how to get the names from each row in the grid to populate all 10 button captions. I did the same thing a while back with populating the captions from a database and that was no problem, but i can't seem to get my head around looping through the grid and the command buttons. Please could someone shed some light on this for me.

    Many thanks in advance

  2. #2
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Button Captions from Flexgrid

    With MSFlexGrid1
    For i = 1 to .Rows - 1 'assuming you have a fixed header row
    cmdDep(i).Caption = .TextMatrix(i,0)
    Next
    End With

  3. #3
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Button Captions from Flexgrid

    Try this:

    vb Code:
    1. Private Sub GetButtonNames()
    2. Dim i As Long
    3.  
    4. For i = 0 To 9
    5.     cmdDep(i).Caption = MSFlexGrid1.TextMatrix(i, 0)
    6. Next
    7.  
    8. End Sub
    Edit: I assumed you have no fixed headers.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Button Captions from Flexgrid

    Thank you so much guys, i knew i was missing something so simple, another question on the same topic, that i have been thinking about, i have 10 command buttons cmdDep and in my grid i have say 30 rows, so when the form loads it populates the captions from the first 10 rows of the grid, i have added a button cmdDown when clicked it must populate the captions with the next 10 rows from the grid and if clicked again populate from the next 10 rows. Any ideas on how i would be able to do this.

    Many thanks

  5. #5
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Button Captions from Flexgrid

    Just store a variable containing the 'latest last number' of the rows you have used.

    Private LastRow as Byte

    Let's say in Form_Activate() you run the code that sets the captions using row 0 to row 9 ... at this point you would do this:

    LastRow = 9

    Then when you click the button you would use

    For i = LastRow + 1 To LastRow + 11
    cmdDep(i - (LastRow + 1)).Caption = MSFlexGrid1.TextMatrix(i,0)
    Next

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Button Captions from Flexgrid

    Quote Originally Posted by Webskater
    With MSFlexGrid1
    For i = 1 to .Rows - 1 'assuming you have a fixed header row
    Don't.
    Code:
    For i = .FixedRows to .Rows - 1
    .FixedCols accounts for fixed columns.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Button Captions from Flexgrid

    Thanks guys.

    All sorted and working great.

    Many thanks once again

  8. #8
    Junior Member
    Join Date
    Jan 2006
    Posts
    29

    Re: Button Captions from Flexgrid

    Quote Originally Posted by alexanderjames
    Hi All

    I am really struggeling with something simple, i have a vsflexgrid with 1 col and 10 rows i then have an array of 10 command buttons cmdDep and i just can't seem to figure out how to get the names from each row in the grid to populate all 10 button captions. I did the same thing a while back with populating the captions from a database and that was no problem, but i can't seem to get my head around looping through the grid and the command buttons. Please could someone shed some light on this for me.

    Many thanks in advance

    How did you put command buttons into the vsFlexgrid?

  9. #9
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Button Captions from Flexgrid

    @dtrade,
    Similar to this way.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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