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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Determine Underlying Field in GridDataBoundGrid column

Thread ID:





1623 Nov 15,2002 03:48 PM UTC Jun 9,2004 12:14 PM UTC WinForms 4
Tags: GridControl
Ivan Pelly
Asked On November 15, 2002 03:48 PM UTC

How can I find out the name of the field that supplies the content for a given column in the GridDataBoundGrid? In the MouseUp Event, I have: Dim row As Long Dim col As Long Dim p As New System.Drawing.Point(e.X, e.Y) Dim dTblColIdx As Integer Grid.PointToRowCol(p, row, col) dTblColIdx = Grid.Binder.ColIndexToField(col) MsgBox(dtbl.Columns(dTblColIdx).ColumnName) When I click in the header of the leftmost column in the grid, the code above sets the variable "col" to 1, and dTblColIdx to 0. But column 0 of the datatable (dtbl) is not the column underlying the leftmost column in the grid (the grid columns have been reordered elsewhere earlier in the code). Thanks.

Administrator [Syncfusion]
Replied On November 15, 2002 05:46 PM UTC

You can get the mappingname from the InternalColumns collection and use that to get at the correct table in teh datatable. Private Sub GridDataBoundGrid1_CellClick(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs) Handles GridDataBoundGrid1.CellClick Dim dTblColIdx As Integer dTblColIdx = GridDataBoundGrid1.Binder.ColIndexToField(e.ColIndex) Dim sName As String = GridDataBoundGrid1.Binder.InternalColumns(dTblColIdx).MappingName() MsgBox(dt.Columns(sName).ColumnName) End Sub

Replied On June 8, 2004 07:53 PM UTC

Hi. I'd like to reopen this old topic... I'm using a GDBG with two rows (similar to your MultiRowRecord example), and the technique you described (see C# version below) works just fine, as long as I'm on the first of my two rows. Unfortunately, when the current cell is in the second row, ColIndexToField thinks it's still in the first row, and I'm indexing the wrong GridBoundColumns as a result. I'm using Grid, and I've manually created my array of GridBoundColumns. Any ideas? I could resort to testing against hardwired column- and row%2 numbers, but if there's a more elegant solution... [C#] int n = Grid.Binder.ColIndexToField(nCol); GridBoundColumn gbc = Grid.Binder.InternalColumns[n]; Thanks, Tom

Administrator [Syncfusion]
Replied On June 8, 2004 08:41 PM UTC

Try this code to see if it gives you what you need. GridHierarchyLevel level0 = this.gridDataBoundGrid1.Binder.RootHierarchyLevel; GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; int rowPos = this.gridDataBoundGrid1.Binder.RowIndexToPosition(cc.RowIndex); int colPos = this.gridDataBoundGrid1.Binder.ColIndexToField(cc.ColIndex); int field = level0.RowFieldToField(rowPos % level0.RowCountPerRecord, colPos); Console.WriteLine(level0.InternalColumns[field].MappingName);

Replied On June 9, 2004 12:14 PM UTC

Bingo! You guys must have the best technical support in the business. Thanks, Tom


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.

Warning Icon 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.Close Icon