How to get the Cell Index in Data Grid Control

G

Guest

I am filling the Data Grid in the existing columns from the database.
In the Item_Command event of the Data Grid I am writing the code to be
execute while clicking on each item in the data grid. It is working. What is
the way for knowing which cell they click. With the item index I can get the
row. How I can get the column?
================Suresh
 
G

Guest

Here is an example of some code I'm using to select a particular column in a
datagrid:

private void subsystemsCellChanged(object sender, MouseEventArgs e)
{
string subsystemSearch = "";
DataGrid.HitTestInfo hitInfo = subsystemsDataGrid.HitTest(new Point(e.X,
e.Y));
if (hitInfo.Row < datatableIndexTab.Rows.Count && hitInfo.Row > -1)
{
subsystemsDataGrid.Select(hitInfo.Row);
subsystemsDataGrid.CurrentCell = new DataGridCell(hitInfo.Row,
hitInfo.Column);
DataGridCell dc = subsystemsDataGrid.CurrentCell;
string txt = subsystemsDataGrid[dc].ToString();
// do more processing here
}
}

HTH

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
 
G

Guest

Hi,
Thanks.
============Suresh

WhiteWizard said:
Here is an example of some code I'm using to select a particular column in a
datagrid:

private void subsystemsCellChanged(object sender, MouseEventArgs e)
{
string subsystemSearch = "";
DataGrid.HitTestInfo hitInfo = subsystemsDataGrid.HitTest(new Point(e.X,
e.Y));
if (hitInfo.Row < datatableIndexTab.Rows.Count && hitInfo.Row > -1)
{
subsystemsDataGrid.Select(hitInfo.Row);
subsystemsDataGrid.CurrentCell = new DataGridCell(hitInfo.Row,
hitInfo.Column);
DataGridCell dc = subsystemsDataGrid.CurrentCell;
string txt = subsystemsDataGrid[dc].ToString();
// do more processing here
}
}

HTH

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT


Suresh.P.R said:
I am filling the Data Grid in the existing columns from the database.
In the Item_Command event of the Data Grid I am writing the code to be
execute while clicking on each item in the data grid. It is working. What is
the way for knowing which cell they click. With the item index I can get the
row. How I can get the column?
================Suresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top