I have a DataGridView with a button that I created that adds a new row to the DataGridView - that works fine. The problem is that when the user clicks that button, the entire cell is selected. In order to allow typing into that cell, the user has to first click in the cell. I'm told this is annoying.
Let me interrupt myself right here and say: If anyone has an easy way to accomplish this, please suggest it. Because what I'm about to describe (i.e. what I am currently trying) seems far too complicated to achieve what seems to be a simple goal...
So... I added the following line to the end of my "btnAddRow_Click" event:
I also hooked the following two methods as follows:
That actually all seems to work well. Until something happens - like they do something to get the DataGridView to be redrawn (I think). Then this exception is thrown:
[tt]Operation is not valid due to the current state of the object[/tt]
I tried to also to call
when the user leaves the tabpage (i.e. the DataGridView is being hidden) - but still got the same error.
Can anyone help me, please?
Thanks!!!
Let me interrupt myself right here and say: If anyone has an easy way to accomplish this, please suggest it. Because what I'm about to describe (i.e. what I am currently trying) seems far too complicated to achieve what seems to be a simple goal...
So... I added the following line to the end of my "btnAddRow_Click" event:
Code:
dgvAnnouncements.Rows[dgvAnnouncements.RowCount - 1].Cells[0].Selected = true;
Code:
private void dgvAnnouncements_CellEnter(object sender, DataGridViewCellEventArgs e)
{
dgvAnnouncements.BeginEdit(false);
}
private void dgvAnnouncements_CellLeave(object sender, DataGridViewCellEventArgs e)
{
dgvAnnouncements.EndEdit();
}
[tt]Operation is not valid due to the current state of the object[/tt]
I tried to also to call
Code:
dgvAnnouncements.EndEdit();
Can anyone help me, please?
Thanks!!!