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
Hi Marc,
If you are causing the data source to send a Reset notification, then all rows in the grid are destroyed and new ones are created for the new data.
To find a row, you will need to loop through the rows in the grid, there's no built-in search functionality in the grid. If you know the position of the row you want in the BindingManager, then you can use that index to find the row in the grid using something like this:
this.ultraGrid1.Rows.GetRowWithListIndex(index);
I have the same scenario here, is it not possible to use the ultragrid1.rows.all.find() function to return the row? since we're resetting the grid, we can capture the field value from the grid prior to the reset.
Theres always the old fallback of looping through each row in the grid, but the Find method seems to be what we're looking for here, isnt it?
Um, I don't think so. I could be wrong, but I am pretty sure that the All property is a property on Collection and it just returns an Object array. I wasn't aware that there was a Find method on an Array, but even if there is, I assume it finds some object that you specify. I don't see how it would be able to find an UltraGridRow with a cell that has a particular value. It knows nothing about the grid or cells.
Mike, marcjannes, fergal1982
I have this same requirement in my project.
The .Find() method is a new LINQ extension for collections. However, because the .All property doesn't know that the items inside the RowsCollection object (UltraGrid1.Rows) are UltraGridRow objects, what seems to be syntactically correct is something like this ...
// 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));
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.
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))