C#:Problem in DataGridView CellMouseClck Event
-
hi all, any body pls help me to solve my problem. Though my code is right (i feel) i couldnt achieve the result i expect , i tried in all means, any one pls solve my headache!.
private void DataGrdVw1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { string CurrentSelValue; CurrentSelValue = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); txtAreaName.Text = CurrentSelValue; }
it doent works!. i tried with cell mouse down event also no use.private void DataGrdVw1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e) { this.GrdText.Text = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); }
i need to show the current cell s text in a text box when the datagridview's cell is clicked with mouse, or arrow keys pls help ksskKSSK
-
hi all, any body pls help me to solve my problem. Though my code is right (i feel) i couldnt achieve the result i expect , i tried in all means, any one pls solve my headache!.
private void DataGrdVw1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { string CurrentSelValue; CurrentSelValue = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); txtAreaName.Text = CurrentSelValue; }
it doent works!. i tried with cell mouse down event also no use.private void DataGrdVw1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e) { this.GrdText.Text = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); }
i need to show the current cell s text in a text box when the datagridview's cell is clicked with mouse, or arrow keys pls help ksskKSSK
Use the DataGridView's CellEnter event, and then use the CurrentCell property: private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { label4.Text = dataGridView1.CurrentCell.Value != null ? dataGridView1.CurrentCell.Value.ToString() : String.Empty; } Notice that I'm also checking here if the cell value is null, and setting the textbox text to String.Empty if it is, otherwise you get a nasty Null Reference Exception when trying to call ToString() a non-existent value.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't. "I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it." -Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.