Answer the question
In order to leave comments, you need to log in
How to prevent automatic sorting when adding a record in DataGridView C#?
On the form, a DataGridView and a ComboBox bound to one of the BindingSource fields that is not displayed in the DataGridView. It looks like this:
groupheadersBindingSource.Sort = "IsTrainer DESC, HeaderTitle ASC";
sportTypeComboBox.DisplayMember = "SportTitle";
sportTypeComboBox.ValueMember = "SportID";
sportTypeComboBox.DataSource = sportTypesBindingSource;
sportTypeComboBox.DataBindings.Add("SelectedValue", groupheadersBindingSource, "SportID");
Answer the question
In order to leave comments, you need to log in
So far I have done Workaround: We declare
two variables:
DataRowView editingRowView = null;
bool addingRow = false;
groupHeadersBindingNavigator.AddNewItem = null;
dataGridView.AllowUserToAddRows = false;
editingRowView = (DataRowView)groupheadersBindingSource.AddNew();
addingRow = true;
void sportTypeComboBox_Click ..
{
if ((editingRowView != null) && (addingRow))
{
groupheadersBindingSource.Position = groupheadersBindingSource.Find("HeaderID", editingRowView.Row["HeaderID"]);
addingRow = false;
editingRowView = null;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question