Question

I am developing a Windows Mobile 6.5 application with C# using Visual Studio 2008 (I'm still a beginner), it's connected to an SQL CE database. However, I want to send the value of a selected cell in the dataGrid connected to my database to a textBox. It looks very possible, but I can't find a cell click event related to the dataGrid control, there is only one for the dataGridView that I think it's only available for the Windows Desktop applications.

Was it helpful?

Solution

First, wire up your click event, by selecting the GridView control and double clicking the Click field located under the Lightening Bolt:

click event

Next, expanding on an answer already posted:

private void dataGrid_Click(object sender, EventArgs e) {
  int row = dataGrid1.CurrentCell.RowNumber;
  int col = dataGrid1.CurrentCell.ColumnNumber;
  textBox1.Text = string.Format("{0}", dataGrid1[row, col]);
}

I use string.Format because sometimes your data could be null or DBNull.Value.

OTHER TIPS

I think you need to handle Click and make use of CurrentCell Property

I believe you want the Control.Click Event

The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. However, the MouseClick event will not be raised if the click is caused by action other than that of the mouse, such as pressing the ENTER key.

private void dataGrid_Click(object sender, EventArgs e)
{
    int row_num = _DataGrid.CurrentCell.RowNumber;
    int col_num = _DataGrid.CurrentCell.ColumnNumber;
    object data = _DataGrid[row_num, col_num];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top