There is the RowIndex property for the CurrentCell property for the DataGridView.
There is the RowIndex property for the CurrentCell property for the DataGridView. Datagridview.CurrentCell. RowIndex Handle the SelectionChanged event and find the index of the selected row as above.
Perfect. This seems simplest/fastest, even over SelectedRows0.Index. Would that be a good assumption?
– ErikE Aug 26 '10 at 18:24 Hmm, I didn't think about multiple rows being selected. I'm not sure of the behaviour of current cell in this case. – fletcher Aug 26 '10 at 18:27 If it's anything like Excel, the selected list can be many rows/columns, but there is only one current/active cell.
I only care about the current row so this should do fine. – ErikE Aug 26 '10 at 18:34.
DataGridView1. SelectedRows0. Index; Or if you wanted to use LINQ and get the index of all selected rows, you could do: dataGridView1.SelectedRows.
Select(r => r. Index).
Helpful (IndexOf was not really "on my radar" yet), but roundabout since getting the row isn't necessary. The . Index method is what I was looking for.
– ErikE Aug 26 '10 at 18:22.
Use the Index property in your DGV's SelectedRows collection: int index = yourDGV. SelectedRows0.Index.
There it is... for some reason I just couldn't find the Index property. Easy money for you! – ErikE Aug 26 '10 at 18:21 Do you think this is better or DGV.CurrentCell.
RowIndex? – ErikE Aug 26 '10 at 18:25.
Try DataGridView. CurrentCellAddress. Returns: A Point that represents the row and column indexes of the currently active cell.E.G.Select the first column and the fifth row, and you'll get back: Point( X=1, Y=5 ).
That returns a Point data type with properties X and Y which return pixel position... I need the row number. – ErikE Aug 26 '10 at 18:23 Erm, my apologies. I misspoke in my ignorance.So advise me, which is better: DGV.
CurrentCellAddress. Y or DGV.CurrentCell. RowIndex?
– ErikE Aug 26 '10 at 18:57 P.S. Since I asked for the row index, things would have been less rocky in our relationship if you'd said DataGridView. CurrentCellAddress. Y ... :) – ErikE Aug 26 '10 at 19:13 I think at this point all of these answers are valid, it's just up to you which one you want to choose that's cleanest for your purposes.
I'd suggest typing up the different implementations and looking at the IL in . NET Reflector (red-gate.Com/products/reflector) if you really want to see what code gets generated for each, but as many will say, that's micro-optimization. It's really down to what's most clear in intent.
PS Note taken to be more clear in future. – Kilanash Aug 26 '10 at 19:35.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.