Hello:
For my UI, I have a ComboBox and a DataGridView. The user will select a Person from the ComboBox, and the DataGridView will display the Person.Schools. Person.Schools is defined as a List<string>.
Here's the code...
BindingSource bs = new BindingSource();
bs.DataSource = listPersons;
this.comboBox1.DataSource = bs;
this.dataGridView1.DataBindings.Add("DataSource", bs, "Schools");
Well, I want the user to interface with the DataGridView and modify the school if needed. This is built-in to the DataGridView; the user can begin typing in the DataGridViewCell. When the user hits the Enter button, the focus will move to the next school, which is located below the previous cell the person is editing.
This is the behavior I want. However, I want to add one last behavior. When the user gets to the last school in the list, which is the last row in the DataGridView, and the user hits enter, I want to move to the next Person in the BindingList.
I've tried the following in the CellFormatting...
if (this.dataGridView1.CurrentCell.RowIndex == this.dataGridView1.Rows.Count - 1)
{
((BindingSource)this.comboBox1.DataSource).Position++; // Don't worry about checking for going past the BindingSource.Count
}
This works, but when it the BindingSource increments its position, the NEXT Person's first school is also changing. EXA: If I have two Persons, Person1 is currently selected. He has two schools. I change the first school for him to "U. of ABC." I hit enter, the UI moves the focus to the next cell. I change this cell to "U. of DEF." I hit enter, well, the CellFormatting event fires and increments the position of the BindingSource. After the position is incremented, I can see on the UI Person2 is in the ComboBox, and the FIRST school in the DataGridView -- although I didn't set it -- is "U of DEF."
How can I change the position of the BindingSource, moving it to the next Person in the list, without changing the first school of the next Person?
Thank you,
Trecius