Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI ALL.....
In my form application , there is a (buttonNEW) that select NewIndexRow of DataGridView.
C#
private void buttonNew_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentRow.Index!=dataGridView.NewRowIndex)
            {
                dataGridView.ClearSelection();
                dataGridView.Rows[dataGridView.NewRowIndex].Selected = true;
                label1.Text = dataGridView.CurrentRow.Index.ToString();
                
            }
        }

but after clicking the button the index of DataGridView does not change.
What is the problem?.....
Posted
Updated 19-Nov-12 19:53pm
v2

1 solution

Hi,

You need to make use of the row the current row, but CurrentRow is readonly, so setting the current cell has the desired effect.

DataGridView.CurrentCell Property[^]

You could also handle this event:
C#
public event EventHandler SelectionChanged
which will notify you if the current selection has changed. This way you can test if the selection has changed.

Kind regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900