Finding TEXT of DataGrid Column

  • Thread starter Thread starter David Elliott
  • Start date Start date
D

David Elliott

I am trapping the MouseDown event and am looking to get the value of the cell
and also the Column name.

I can get the value of the cell with the code below. I can also get the Column name
if the DataGrid has a TableStyle. The problem comes when the DataGrid uses the
default TableStyle.

Using the debugger I walked down the class structure and could find the information
at this point
dataGrid1.Controls[hti.Column].dataGrid.defaultTableStyle.gridColumns.List._items
I can't seem to find my way there at design time, programmatically.

Any help would be appreciated.

Dave
(e-mail address removed)

=======================================================

if (e.Button == MouseButtons.Right)
{
DataGridTableStyle ts1;

gridBoxText = "";
if (hti.Type == DataGrid.HitTestType.Cell)
{
gridBoxText = dataGrid1[hti.Row, hti.Column].ToString();

ts1 = dataGrid1.TableStyles["JobRecordCollection"];

if (ts1 != null)
gridHdrText = ts1.GridColumnStyles[hti.Column].HeaderText;
else
gridHdrText = dataGrid1.Controls[hti.Column].Text;
}
else if (hti.Type == DataGrid.HitTestType.ColumnHeader)
{
gridHdrText = dataGrid1.Controls[hti.Column].Text;
}
}
}
 
I have in fact bound the grid to a class derived from CollectionBase.

When I display the DataGrid, the order of the columns is NOT the order that
is defined in the class. The compiler must be doing some optimizations.

I am unclear as to what you are suggesting as a possible solution. What do
you mean when you say query all public instance properties of an object at
index 0 and obtain the name of the prpoerty having index equal to the column
number?

Thanks,
Dave
 
Back
Top