Okay so I know this is probably an easy question but I am tired and I want to find a good way to do this. The code below will show what I am getting into (I'll explain more after it)

string loc = dataGridView1.SelectedRows.ToString();
int loc2 = Convert.ToInt32(loc);

Anyway this little code goes into a if loop and has to deal with removing data off a datagridview without the risk of the user not clikcing anything and having it go into, a null pointer issue. I but the the think it when the I do that second line of code it has thrown this error "Input string was not in a correct format". I know I have run into this error and just went around it but now I want to find a proper way to do this

Recommended Answers

All 2 Replies

SelectedRows is a collection.
If you debug you will find that loc == "System.Windows.Forms.DataGridViewSelectedRowCollection"

Thanks for pointing that out yeah I fixed it with this line

int loc = dataGridView1.CurrentCellAddress.Y;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.