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
close icon

Determine Underlying Field in GridDataBoundGrid column

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.

4 Replies

AD Administrator Syncfusion Team 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


TJ TJ 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 2.0.5.0, 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


AD Administrator Syncfusion Team 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);


TJ TJ June 9, 2004 12:14 PM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon