I have a UltraWinGrid where I have set the RowSelectorHeaderStyle to None so that the row selector column does not show. I have also set the grids SelectTypeRow to Extended in order to allow the selection of multiple rows.
In order to allow the user to select a row, I have them click on another cell and then set the row of the clicked cell to "selected" via the following code:
Private Sub ugRouting_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ugRouting.MouseClick
Dim aUIElement As Infragistics.Win.UIElement = ugRouting.DisplayLayout.UIElement.ElementFromPoint(New Point(e.X, e.Y))
Dim aRow As UltraGridRow = aUIElement.GetContext(GetType(UltraGridRow))
Dim aCol As UltraGridColumn = aUIElement.GetContext(GetType(UltraGridColumn))
If aCol.Key = "Status" Then ugRouting.Rows(aRow.Index).Selected = True
This works fine when the user initially selects a row. However, when they select a second row, the Selected property of the first row is somehow changed to False someplace (even before it enters the MouseClick subroutine the second time).
My question is: why is the Selected property being changed to False for the first row, and how can I prevent this from happening.
Thanks for any assistance.
Steve Smith said:I don't know about why your first row is no longer selected after the second row, but I was thinking that if you changed your column's CellClickAction to RowSelect that it may solve the problem. I didn't test it out so I'm just rolling that off the top of my head.
Yeah, that's a better way to do it. :)
sch said:I have a UltraWinGrid where I have set the RowSelectorHeaderStyle to None so that the row selector column does not show. I have also set the grids SelectTypeRow to Extended in order to allow the selection of multiple rows.
RowSelectorHeaderStyle only affects the Header of the RowSelectors, it doesn't hide the RowSelectors themselves. For that, you are probably setting the RowSelectors property. :)
sch said:My question is: why is the Selected property being changed to False for the first row, and how can I prevent this from happening.
Instead of setting Selected=True on the row, try using grid.Selected.Rows.Add to add it to the collection.
Also, make sure SelectTypeRow is set to a value that allows the selection of multiple rows.
The top of your head is very smart (I can only imagine what the middle is like!). That did it. An added bonus is, that your solution also allows me to get rid of my whole MouseClick method. Less code is always better.
While that solves the problem, it would be interesting to know what is deselecting my first row the way I am doing it.
Thanks very much, Steve.
I don't know about why your first row is no longer selected after the second row, but I was thinking that if you changed your column's CellClickAction to RowSelect that it may solve the problem. I didn't test it out so I'm just rolling that off the top of my head.