Results 1 to 13 of 13

Thread: [RESOLVED] Get Value of The Respective MSHFlex Grid Row Using ComboBox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Resolved [RESOLVED] Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Hello! Few days earlier, I've posted a thread regarding ComboBox inside MSHFlex grid. I am trying to update rows of MSHFlex grid using ComboBox individually inside it. So What my thinking is to loop through the grid and get the row number to update using ComboBox. So What I tried is the following:

    Code:
    Private Sub Combo2_Click(Index As Integer)
        For i = 1 To (MSHFlexGrid2.Rows - 1)
            If i > Combo2.UBound Then
                Load Combo2(i)
            End If
        
            Combo2(i).Visible = True
           
            Combo2(i).Clear
            With Combo2(i)
               .AddItem "Pringles"
               .AddItem "Denim"
            End With
            
            Dim o As Integer
            o = MSHFlexGrid2.Row 'It just gets the last row number and updates it
            
            MSHFlexGrid2.TextMatrix(o, 3) = txtID.Text
        Next i
    End Sub
    This is the scenario (Given image below - There are four rows each having one ComboBox attached. So if I choose any of the ComboBoxes, it only updates the last index or row) and is there any other better way to get the associated row number with ComboBox with loop or without it?

    Name:  2.jpg
Views: 338
Size:  39.9 KB

    Note: Currently no database is used. The update is done only in MSHFlex grid instantly. For demo purpose, I am using the TextBox value - txtID to be updated using ComboBox right now. For an example, if I put 10 in the TextBox and use the respective ComboBox of row 2 & 4, then the 4th column of those rows will be populated with 10.
    Last edited by AT-2017; Apr 16th, 2017 at 11:10 AM.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,177

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Is not your combobox index the same as the row to which you refer?

    IOW,
    Code:
    MSHFlexGrid2.TextMatrix(Index, 3) = txtID.Text

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Hello @SamOscarBrown! Thanks for the reply. The indexes are the same and I hope, this is correct one as the ComboBoxes are associated with respective rows. But it doesn't update or get the exact rows when I choose any of the ComboBoxes. It just works fine for the last index 4 (As shown in the image). Updated the original post a little bit.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    I think you are misunderstanding Sam.

    MSHFlexGrid2.Row refers to the currently selected/active row in the grid. If the row is not correct, you need to change its value to the row you want to edit. If you don't want to change the row, but update a different row, that's where Sam's suggestion comes into play. MSHFlexGrid2.TextMatrix updates any row, not necessarily the current row,column

    In your original post, the variable o references the current row which appears to be the last row. So MSHFlexGrid2.TextMatrix(0, 3) always updates the last row. And MSHFlexGrid2.TextMatrix(Index, 3) should update column 3 of the row relative to the clicked combobox.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,067

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    @AT-2017: You'll have to take into account that in the way you are doing this, you cannot show in the grid more rows than the number of rows that the grid can show without displaying the vertical scrollbar.
    If the grid become scrollable, it will get more complex to place the comboboxes properly over the right cell (and what index to use when the combos are loaded, to respond to the Scroll event, Etc.)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    That's a perfect solution and I tried that earlier using the row indexes something like this:

    Code:
    MSHFlexGrid2.TextMatrix(i, 3) = txtID.Text
    Where i refers to the row indexes of the grid but it updates all the rows if any of respective ComboBox is selected.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Of course, since you are looping thru each row of the grid, i refers to each row and therefore MSHFlexGrid2.TextMatrix(i, 3) would update each row.

    I'm not sure why you are looping. Your code should look the following if I am understanding your question. This is what Sam was suggesting. And adding/removing comboboxes to the grid should be in a different routine, in my opinion.
    Code:
    Private Sub Combo2_Click(Index As Integer)
            MSHFlexGrid2.TextMatrix(Index, 3) = txtID.Text
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    So what you are trying to explain is looping not required at all and the index will get the related row values selecting the associated ComboBox. OK. I'll be trying it and let know.

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,177

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Quote Originally Posted by Eduardo- View Post
    @AT-2017: You'll have to take into account that in the way you are doing this, you cannot show in the grid more rows than the number of rows that the grid can show without displaying the vertical scrollbar.
    If the grid become scrollable, it will get more complex to place the comboboxes properly over the right cell (and what index to use when the combos are loaded, to respond to the Scroll event, Etc.)
    Precisely....that is why "I" would never put comboboxes in a grid...just too much (for me) to code to. But then, hey, that's just me. Would rather use the approach I suggested earlier...fill ONE combobox per column based upon the row/column of the grid selected. So much simpler and easier on the eye for users.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    @SamOscarBrown! I am trying to understand what you have written and others as well. It's just for demo purpose. I've your valuable suggestion given earlier. Cheers!

  11. #11
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,067

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Quote Originally Posted by SamOscarBrown View Post
    Precisely....that is why "I" would never put comboboxes in a grid...just too much (for me) to code to. But then, hey, that's just me. Would rather use the approach I suggested earlier...fill ONE combobox per column based upon the row/column of the grid selected. So much simpler and easier on the eye for users.
    Yes... it involves some code to do it properly.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Yeah @Eduardo-. A bit programming required. I was actually trying to use the VB grid same as the GridView in ASP.NET. Almost similar but GridView seems much easier. I try to implement something like this (Seen in a project) and don't know exactly what has been used - http://s15.postimg.org/f50umxo6z/output_o_RHj_SM.gif. As an alternate, I chose the MSHFlex grid but the control in the image isn't a grid, I guess.
    Last edited by AT-2017; Apr 16th, 2017 at 09:35 PM.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    66

    Re: [RESOLVED] Get Value of The Respective MSHFlex Grid Row Using ComboBox

    Thanks to all and the following solution worked perfectly:

    Code:
    Private Sub Combo2_Click(Index As Integer)
            MSHFlexGrid2.TextMatrix(Index, 3) = txtID.Text
    End Sub
    I would request to inform if anyone knows about the following control or anything similar to it:

    http://s15.postimg.org/f50umxo6z/output_o_RHj_SM.gif

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