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.

Getting ColumnName from BoundDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

13027 Apr 19,2004 06:44 AM Apr 21,2004 12:16 PM Windows Forms 8
loading
Tags: GridControl
Vincent Lo
Asked On April 19, 2004 06:44 AM

Hi, Could anyone shed me some light on how i can retrieve information about what column (column name) i am looking at when i click on a BoundDataGrid?

Satish
Replied On April 19, 2004 06:53 AM

Use the following code to get the columnName. private void gridDataBoundGrid1_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e) { GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; int field = this.gridDataBoundGrid1.Binder.ColIndexToField(cc.ColIndex); string mappingName = this.gridDataBoundGrid1.Binder.InternalColumns[field].MappingName; MessageBox.Show(mappingName); } Thanks Satish >Hi, > >Could anyone shed me some light on how i can retrieve information about what column (column name) i am looking at when i click on a BoundDataGrid?

Vincent Lo
Replied On April 19, 2004 07:39 AM

Thanks! what should i do if i have got 2 GridHierarchyLevel of data? How can i recogize which hierarchy does that row belongs to? Since the dataGrid''s binder only binds to root hierarchy?

Administrator [Syncfusion]
Replied On April 19, 2004 06:09 PM

You can get the GridBoundRecordState object for the given row using GridBoundRecordState rs = this.grid.Binder.GetRecordStateAtRowIndex(rowIndex); The GridBoundRecordState has a LevelIndex property.

Vincent Lo
Replied On April 20, 2004 02:21 AM

Thanks, I am able to know which hierarchy i am in but how i can get the underlying dataRow from this info? In my cell_click I have got this piece of code: CurrencyManager cm; GridBoundRecordState rs = gridBinder.GetRecordStateAtRowIndex(e.RowIndex); cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource, this.dataSet.Tables[rs.LevelIndex].TableName]; DataRow dr = ((DataRowView)cm.Current).Row; GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; int field = this.gridDataBoundGrid1.Binder.ColIndexToField(cc.ColIndex); string mappingName; if (rs.LevelIndex == 0) { mappingName = ghlMkt.GridBoundColumns[field].MappingName; } else { mappingName = ghlMktSub.GridBoundColumns[field].MappingName; } Console.WriteLine(mappingName+" "+ dr[mappingName].ToString()); >You can get the GridBoundRecordState object for the given row using > >GridBoundRecordState rs = this.grid.Binder.GetRecordStateAtRowIndex(rowIndex); > > >The GridBoundRecordState has a LevelIndex property.

Vincent Lo
Replied On April 20, 2004 02:21 AM

Thanks, I am able to know which hierarchy i am in but how i can get the underlying dataRow from this info? In my cell_click I have got this piece of code: CurrencyManager cm; GridBoundRecordState rs = gridBinder.GetRecordStateAtRowIndex(e.RowIndex); cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource, this.dataSet.Tables[rs.LevelIndex].TableName]; DataRow dr = ((DataRowView)cm.Current).Row; GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; int field = this.gridDataBoundGrid1.Binder.ColIndexToField(cc.ColIndex); string mappingName; if (rs.LevelIndex == 0) { mappingName = ghlMkt.GridBoundColumns[field].MappingName; } else { mappingName = ghlMktSub.GridBoundColumns[field].MappingName; } Console.WriteLine(mappingName+" "+ dr[mappingName].ToString()); >You can get the GridBoundRecordState object for the given row using > >GridBoundRecordState rs = this.grid.Binder.GetRecordStateAtRowIndex(rowIndex); > > >The GridBoundRecordState has a LevelIndex property.

Vincent Lo
Replied On April 20, 2004 02:22 AM

ghlMkt is the parent GridHierarchyLevel, ghlMktSub is the child GridHierarchyLevel

Vincent Lo
Replied On April 20, 2004 03:02 AM

Thanks, I have solved it using the following code GridBoundRecordState rs = gridBinder.GetRecordStateAtRowIndex(e.RowIndex); CurrencyManager cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember]; DataRowView drv = (DataRowView) cm.Current; DataRow dr = drv.Row; if (rs.LevelIndex > 0) { dr = dr.GetChildRows(mDataSet.Relations[0])[rs.Position]; } GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; int field = this.gridDataBoundGrid1.Binder.ColIndexToField(cc.ColIndex); string mappingName; if (rs.LevelIndex == 0) { mappingName = ghlMkt.GridBoundColumns[field].MappingName; } else { mappingName = ghlMktSub.GridBoundColumns[field].MappingName; } Console.WriteLine(mappingName+" "+ dr[mappingName].ToString()); } catch (Exception er) { Console.WriteLine(er.Message); } Could you advise if such code could be simplified a bit?

Administrator [Syncfusion]
Replied On April 21, 2004 12:16 PM

The GridBoundRecordState has a reference to the Table and the position of the record in this table. So, you might try code like: DataRowView drv = rs.Table[rs.Position] as DataRowView; to see if that gives you what you want. (I think the returned item is a DataRowView but you could check its type to see if something else is being returned in your case.)

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.

;