-1

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)

Marcel
  • 917
  • 3
  • 19
  • 48

1 Answers1

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