Reputation: 331
I have a DataGridView
which is bound to a SQL result. Afterwards I add three DataGridViewComboBoxColumns
manually, which are populated by corresponding SQL results.
When choosing an entry from each of the DataGridViewComboBoxCells
, the ValueMember
is saved to the database.
As soon as the DataGridViewComboBoxColumns
are added, a preselect function is called, which reads the selected values from the database, to always see the last state.
Until now everything is working as expected.
The problem is, as soon as I sort the DataGridView
by clicking on any of the column heads, the DataGridViewComboBoxCells
are not preselected any more.
So, I thought, by adding a .Sorted
event handler which calls my preselect function would solve this problem. But the selection is not done any more.
function PreselectComboBoxes(int IdJob) {
foreach (DataGridViewRow row in dataGridViewHotels.Rows)
{
... // iteration through all rows and set value read from database by reading ID number from first column
}
}
As the ID for the database can be read directly from the row, I do not see, why it does not work this way.
Thanks in advance for any ideas.
Upvotes: 0
Views: 40