Reputation: 5705
Having 1 datagridview for products and 1 combobox for categories, I have set combobox selected value to CategoryID.
When I type in the combobox the first letters of the category name and press Enter the name is completed inside the combobox, but the relative field in the datagridview doesn't change until I click outside the combo.
Please, is there a way to make pressing Enter key perform change in the datagridview, so that I can save modification directly on save button click.
Upvotes: 0
Views: 2069
Reputation: 5705
I could update the categoryID in the Product bindingsource simultanuously at pressing "Enter" key on combo Autocomplete, by using the next event : cboCategories_SelectedValueChanged as follows:
private void cboCategories_SelectedValueChanged(object sender, EventArgs e)
{
int val = Convert.ToInt32(cboCategories.SelectedValue);
ModifGrid(val);
}
private void ModifGrid(int ModifiedValue)
{
if (Convert.ToInt32(productBindingSource.Count)>0)
{
((Product)productBindingSource.Current).CategoryID = ModifiedValue;
}
}
After clicking save button in the bindingsourceNavigator changes are persisted to the database.
Upvotes: 0
Reputation: 26396
This way the gridview could be filled from any source by calling FillGrid()
private void FilterComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
string selText = FilterComboBox.SelectedValue.ToString();
FillGrid(selText);
}
private void FillGrid(string filterValue = "0")
{
//GetDefaultValues(if filtervalue = 0)
//else GetValues(based On Selected category)
//Bind Values to Grid
}
Upvotes: 1