how to get the cell value of a DataGridView 's click event
-
scenario: when i click the datagridview's cell, immediately i need to pass this cell to a WHERE condition to select the remaining fields of the same row.(ie)the gridcell value is an ID value , remaining fields of the ID should be retrieved to textboxes. I wrote code as private void DataGrdVw1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dsGridToTxtBx == obj._selectGridCellAreaDetails(DataGrdVw1.CurrentCell.Value.ToString())) { txtAreaName.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[1].ToString(); txtRegion.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[2].ToString(); txtLocORinterSt.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[3].ToString(); } } Pls help me. I cant trace the datagridview's click event. My above code has no effect in form. :((
ssk
-
scenario: when i click the datagridview's cell, immediately i need to pass this cell to a WHERE condition to select the remaining fields of the same row.(ie)the gridcell value is an ID value , remaining fields of the ID should be retrieved to textboxes. I wrote code as private void DataGrdVw1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dsGridToTxtBx == obj._selectGridCellAreaDetails(DataGrdVw1.CurrentCell.Value.ToString())) { txtAreaName.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[1].ToString(); txtRegion.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[2].ToString(); txtLocORinterSt.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[3].ToString(); } } Pls help me. I cant trace the datagridview's click event. My above code has no effect in form. :((
ssk
Hi, First of all check whether the Handler you have defined is handling the cell's content click. It will be called only when you click on the cell's content. Its better to define a Handler for CellClick Event. To access the current cell's value you can use following : GridView1.CurrentRow.Cells("ID").Value
Regards, Ujjaval Modi