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.

Converting primary key & Column Name to grid row & column indices

Thread ID:





27312 Apr 8,2005 06:32 PM Apr 8,2005 07:41 PM Windows Forms 1
Tags: GridControl
Lori S. Pearsall
Asked On April 8, 2005 06:32 PM

I''m recording the ID of a record and the name of the column. I need to retrieve the corresponding row & column indexes for the represented grid cell. The code (shown below) works for grids with one row per record, but I can''t seem to find the information needed to adjust the indices when there''s two rows per record. FindRowID() ----------- tring primaryKeyColumnName = ((DataTable)(this.Binder.DataSource)).PrimaryKey[0].ColumnName; int gridRowIndex = 0; CurrencyManager cmGrid = (CurrencyManager)this.BindingContext[this.DataSource,this.DataMember]; for (int i = 0; i < this.Binder.RecordCount; i++) { DataRowView drvGridDataRow = (DataRowView) cmGrid.List[i]; if ((Guid)drvGridDataRow[primaryKeyColumnName] == guidPrimaryKeyValue) { gridRowIndex = (i*(this.Model.Rows.HeaderCount+1)) + this.FirstDataRow; break; } } ------------------------------------------------ Note: FirstDataRow is contains # of data rows/rec FindColumnNum() --------------- int intColumnNum = this.NameToColIndex(strColumnName); ------------------------------------------------

Administrator [Syncfusion]
Replied On April 8, 2005 07:41 PM

If you know the column name, colName, and the position in the CurrencyManager, recPosition, then try this code:
int field = this.gridDataBoundGrid1.Binder.NameToField(colName);
int rowIndex = this.gridDataBoundGrid1.Binder.ListManagerPositionToRowIndex(recPosition);
int rowOffSet;
int colIndex = this.gridDataBoundGrid1.Binder.GetHierarchyLevel(0).FieldToRowField(field, out rowOffSet);//.NameToColIndex("City"));
rowIndex += rowOffSet;
if(this.gridDataBoundGrid1.Binder.GetHierarchyLevel(0).RowCountPerRecord == 0)
	colIndex += 1;
Console.WriteLine("col={0} row={1}", colIndex, rowIndex );


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.