Hello,
after I refresh my grid (resetting datasource and putting the new oen), I want to preserve the row selection.
How can i find a particular row from the datasource and make it the activerow,
tx
Marc
emz,
Thanks for that bit of code and the explanation, it's quite thorough. Got some questions for you: (1) is that really any faster than a foreach loop? According to the MSDN documentation the List<T>.Find method is linear in its search, so how does the optimized CLR achieve find the item any faster? It has to go through all the same items one by one starting at the beginning, just like a foreach loop, and it has to run the same comparison you would use in a foreach loop (row.Cells["ColumnKey"].Text.Equals("Stuff"), for example).
Question (2): Have you considered just using the Single method? Here is what I use in my code:
grid.Rows.Single(row => row.GetCellValue("ColumnKey").ToString() == valueToFind.ToString()).Selected = true;
While Single doesn't work when more than one element in the source with the correct value exists, I assume since we're trying to select a single row, it's going to be off a unique column. (We could use Where otherwise).
I'm very new to LINQ, so this is still a learning process for me and I would appreciate any input.
Thanks,
J
Although this thread looks a bit old I thought I would show my approach which seems to be working well:
gridBindingSource.Position = gridBindingSource.Find("ColumnName", SearchValue))
emz said: // get the row from the grid which represents the column for which the filter was modified. UltraGridRow colRow = this.ActiveGrid.Rows.OfType<UltraGridRow>().ToList().Find(row => row.Cells[0].Text.Equals(valueListColumnFiltersChangedEventArgs.Column.Name, StringComparison.CurrentCultureIgnoreCase));
I am using VB.NET and came up with this piece of code:
Dim rowFinder As RowFinder = New RowFinder(<UltraWebGrid instance here>.Rows.OfType(Of Infragistics.WebUI.UltraWebGrid.UltraGridRow)().ToList(), <ItemId here>)
Dim selectedRow As Infragistics.WebUI.UltraWebGrid.UltraGridRow = rowFinder.RetVal
Public Class RowFinder
Public RetVal As Infragistics.WebUI.UltraWebGrid.UltraGridRow
Private _itemIdToFind As String
Public Sub New(ByVal listRows As List(Of Infragistics.WebUI.UltraWebGrid.UltraGridRow), ByVal itemIdToFind As String)
_itemIdToFind = itemIdToFind
RetVal = listRows.Find(AddressOf CompareItemID)
End Sub
Private Function CompareItemID(ByVal row As Infragistics.WebUI.UltraWebGrid.UltraGridRow) As Boolean
Return CStr(row.Cells.FromKey("ItemID").Value) = _itemIdToFind
End Function
End Class
Apparently VB.NET doesn't support anonymous delegates. See this thread.
Thanks Mike - that's a great method - not sure when it was added, but I had totally missed it.
grid.Rows.GetAllFilteredInNonGroupByRows