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.
Unfortunately, activation email could not send to your email. Please try again.

Resolving a DataRow back to is GDBG position

Thread ID:

Created:

Updated:

Platform:

Replies:

25435 Feb 25,2005 05:27 PM Feb 25,2005 07:00 PM Windows Forms 1
loading
Tags: GridControl
Dave Butler
Asked On February 25, 2005 05:27 PM

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!

Administrator [Syncfusion]
Replied On 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); }

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;