I would like to select the "first" row in a grid when it is initially populated. I have been doing this successfully with the following code:
If (firstRow IsNot Nothing) Then
firstRow.Selected = True
End If
I have now introduced a new grid, in which grouping has been switched on at design time. When grouping is enabled, the first (unexpanded) group is selected (or maybe active), which is OK.
What I don't understand is that if the user switches off grouping, FirstRow is an UltraGridGroupByRow and the above code does not select the first real row (although it appears that it is the active row).
I have tried to compare the properties of the 2 types of grid to determine which property is creating this behaviour, but I haven't been able to. Can someone tell me which it is? I'd then like to modify the code above so that it will definitely select the first row when grouping is switched off.
Thanks.
Instead of getting it off of the RowScrollRegion, why not just look at grid.Rows(0)? This could still be a GroupByRow when grouped, but I'm not sure why the other property would return a GroupByRow if you're no longer grouped, unless the grid has not repained yet (and therefore not recalculated the rows).
-Matt
Thanks for your quick reply Matt.
The reason I chose to use the RowScrollRegion.FirstRow was that the documentation states that this provides "the first VISIBLE row", which I took to mean that filtered out rows etc. would not be returned. Early on in my investigations, I changed to grid.Rows(0) and this still returned the same row (ie a groupByRow) when I was no longer grouped.
I wonder if I am switching on/off grouping incorrectly. At the moment, in a right-click context menu, I'm doing the following when the user clicks on the option "Group By This Column" or "Don't Group By This Column"
If (_contextColumn IsNot Nothing) Then If (_contextColumn.IsGroupByColumn) Then ' Column is GroupBy, so make it not _contextColumn.Band.SortedColumns.Remove(_contextColumn) Else ' Column is not GroupBy, so group on it _listGrid.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy _listGrid.DisplayLayout.GroupByBox.Hidden = False Dim descending As Boolean = (_contextColumn.SortIndicator = SortIndicator.Descending) _contextColumn.Band.SortedColumns.Add(_contextColumn, descending, True) End If End If
I would think that this should work. At what point are you trying to access the rows collection? As I said, the rows might not have regenerated yet, as they are not until the grid repaints, so this could be causing the issue. Is the Column associated with the GroupByRow that you have the old column that you've removed from the sorted columns collection?
Thanks Matt, I think you've got it. It looks like I'm trying to do the row selection too early.
The GroupBy effect is because at the time that I am selecting the row, the user's grid settings have not been applied (I'm doing a SaveAsXml and then restoring next time the form is used). Hence, the grid is reflecting it's design mode settings. I put the call in the Shown event of the form and that resolves the issue.
Thanks again. Infragistics support is fantastic!