I have some trouble with setting the last row in my datagridview selected. I select the last row this way:
if (grid.Rows.Count > 0)
{
try
{
gr
It's very easy. use:
dataGridView.CurrentCell=dataGridView[ColumnIndex, RowIndex];
dataGridView[X,y]...
instead of
dataGridView[Y, X]...
I know this may be a little late but it may be of use to someone else.
Have you tried this :
grid.Rows.Row[grid.Rows.Count -1].Selected = true;
In my windows app I first used your code in my datagridview and I got the same exception.. and then it came to me at night when I was in my bed (I'm a newbie to programming).
If I write as : Rows[Rows.count-1]
the first row is "0" and "0-1 = -1" so its out of range :)
Then when I changed my code to Rows.Row[index]
it worked! :)
An alternative if you use c# 3.0 and higher: check out CellAddress(); ;)
Sincerely