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
DavidElliott@BellSouth.net

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

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;
}
}
}

Re: Finding TEXT of DataGrid Column by David

David
Thu Aug 21 07:27:47 CDT 2003

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

On Thu, 21 Aug 2003 09:47:21 +0300, "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> wrote:

>Hi David,
>
>You cannot access this default table style as it is declared as private. I
>have bumbed into a similar problem and was quite disappointed with the fact
>that one has no way to access the default table style. However, I think we
>can safely assume that a grid column is created for each data table column
>in the same order, so as we have data grid column number, we can query the
>data table column with the same index to obtain its name (again, equal to
>the name of the grid column by default).
>
>Things get more complicated if you bound your grid to an ArrayList of an
>ICollection, you would have to query all public instance properties of an
>object at index 0 and obtain the name of the property having index equal to
>the column number. In other words, suppose we have a collection of simple
>classes having two properties - X and Y. Therefore, DataGrid would create
>two grid columns by default - "X" at index 0 and "Y" at index 1 (provided
>that the class properties have the same order in the metadata, of course).
>
>Hope this helps.