I have a Datagridview which contains checkboxes in the first column, and text in the second. When a Checkbox is clicked, the "CellValueChanging"-method is getting the index of the specific row. How do I get the matching string-text? the Column-index of the text is always the same (1)
Asked
Active
Viewed 642 times
-1
-
how about telling the reason for the downvote? -.- – Marcel Feb 04 '15 at 09:37
-
i did'nt voted down but you should show your code how you tried and what you did – Ehsan Sajjad Feb 04 '15 at 09:40
-
that was no offense on you, I'm thankful for your information. But in this case I didn't see any necessity on adding code since it is not depending on that code – Marcel Feb 04 '15 at 09:48
-
you can show atleast `ValueChanged` event – Ehsan Sajjad Feb 04 '15 at 10:34
-
okay, that's a point. That was what I meant, with Feedback I can improve, thank you – Marcel Feb 04 '15 at 10:43
1 Answers
0
You can use GetRow()
method to get row:
var row = TaskGridView.GetRow(1) as YourModel;
using ValueChangedEvent:
private void TaskGridView_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
if (e.RowHandle < 0)
return;
var row = TaskGridView.GetRow(e.RowHandle) as YourModel;
}
for speicific column you can do:
private void TaskGridView_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
if (e.RowHandle < 0)
return;
var row = TaskGridView.GetRow(e.RowHandle) as YourModel;
if (e.Column.FieldName.Equals("YourFieldName", StringComparison.InvariantCultureIgnoreCase))
{
// do something here
}
}

Ehsan Sajjad
- 61,834
- 16
- 105
- 160