We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Resolving a DataRow back to is GDBG position

Given a particular DataRow (identified by primay key value), I''m attempting to determine its location in a GridDataBoundGrid (which is not display the primary key value). Here''s the code scenario: myTable.Columns["PrimaryKey"].ColumnMapping = MappingType.Hidden; myGrid.DataSource = dt; Now given: DataRow dr = dt.Rows.Find(pkValue); CurrencyManager cm = (CurrencyManager) grid.BindingContec[grid.DataSource, grid.DataMemeber]; DataView dv = (DataView) cm.List; Is there any hope of resolving the DataRow position in the grid given the available information? Applying a sort to the DataView and using the DataView.FindRow method is not an option, as the user can change the sort order (which must be preserved). Also, the columns being displayed in the grid do not necessarily have a column or combination of columns that are unique. Any help would be greatly appreciated!

1 Reply

AD Administrator Syncfusion Team February 25, 2005 07:00 PM

The only way I would know to find the row in the grid is to loop through cm.List looking for the primary key value from the DataRow you are seeking. //dr holds the DataRow to be found string pkCol = "Col1"; CurrencyManager cm = (CurrencyManager)this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember]; int i = 0; object pkValue = dr[pkCol]; foreach(DataRowView drv in cm.List) { if(drv[pkCol].Equals(pkValue)) break; i++; } if(i < cm.List.Count) { int gridRowIndex = this.gridDataBoundGrid1.Binder.PositionToRowIndex(i); Console.WriteLine("found at row {0}", gridRowIndex); }

Loader.
Live Chat Icon For mobile
Up arrow icon