Search code examples
c#visual-studiovisual-studio-2010datagridviewdelete-row

Cannot convert from 'System.Windows.Forms.DataGridViewRow' to 'int'


When I try to do this:

var row = datagrid.CurrentRow; name.RemoveAt(row);
(name is a list of strings)

This error appears "Cannot convert from 'System.Windows.Forms.DataGridViewRow' to 'int'"

I need to convert the row to int so I can delete it.


Solution

  • A DataGridViewRow is not an integer but you can get the Index of the row:

    name.RemoveAt(row.Index);