Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone!

I am trying to implement in a datagridview the ability to tab to the next cell within a row. I currently have a combobox (not part of the datagridview) laying over the text box cells. We needed that based on the fact that what we were looking for was not possible with the datagridview combobox cells.

Here is what I have so far to accomplish the tabbing from one cell to another:

C#
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
     if ((dataGridView1.CurrentCell.ColumnIndex > 0) && (dataGridView1.CurrentCell.ColumnIndex <= 7))
     {
          dataGridView1.ClearSelection();
          dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
          vehicleGridComboBox.Location = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
     }
     else if (dataGridView1.CurrentCell.ColumnIndex > 7)
     {
          vehicleGridComboBox.Hide();
     }
}


The issue I'm running into is is that I'm getting this error with the text:
System.InvalidOperationException was unhandled
Message=Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

Does anyone know what this means? The error is pointing to the line below "datagridview1.clearselection()".

Thanks everyone!
Posted
Updated 22-Jul-13 6:31am
v2
Comments
Payrok 22-Jul-13 13:34pm    
Looks like "dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;" is possibly causing the CellEnter event to retrigger.

1 solution

My thanks to Payrok. I removed the offending line and it works where the combobox follows the selected tab now instead of staying put.
 
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