-
Apr 16th, 2017, 06:25 AM
#1
Thread Starter
Lively Member
[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?
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.
-
Apr 16th, 2017, 06:45 AM
#2
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
-
Apr 16th, 2017, 09:18 AM
#3
Thread Starter
Lively Member
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.
-
Apr 16th, 2017, 10:32 AM
#4
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.
-
Apr 16th, 2017, 10:46 AM
#5
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.)
-
Apr 16th, 2017, 11:17 AM
#6
Thread Starter
Lively Member
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.
-
Apr 16th, 2017, 11:21 AM
#7
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
-
Apr 16th, 2017, 12:10 PM
#8
Thread Starter
Lively Member
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.
-
Apr 16th, 2017, 12:23 PM
#9
Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox
Originally Posted by Eduardo-
@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.
-
Apr 16th, 2017, 12:54 PM
#10
Thread Starter
Lively Member
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!
-
Apr 16th, 2017, 01:02 PM
#11
Re: Get Value of The Respective MSHFlex Grid Row Using ComboBox
Originally Posted by SamOscarBrown
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.
-
Apr 16th, 2017, 01:33 PM
#12
Thread Starter
Lively Member
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.
-
Apr 17th, 2017, 04:41 AM
#13
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|