简体   繁体   English

具有选定值和自动完成功能的组合框

[英]Combobox with selected value and Autocomplete

Having 1 datagridview for products and 1 combobox for categories, I have set combobox selected value to CategoryID. 有1个产品的datagridview和1个类别的组合框,我已将组合框选择的值设置为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. 当我在组合框中键入类别名称的第一个字母并按Enter时,该名称将在组合框中完成,但是直到我在组合外部单击时,datagridview中的相对字段才会更改。

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. 请,有一种方法可以使按Enter键在datagridview中执行更改,以便我可以在单击保存按钮时直接保存修改。

This way the gridview could be filled from any source by calling FillGrid() 这样,可以通过调用FillGrid()从任何来源填充gridview

    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
   }

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: 通过使用下一个事件,可以通过在组合自动完成上按“ Enter”键同时更新Product绑定源中的categoryID:cboCategories_ SelectedValueChanged ,如下所示:

    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. 在bindingsourceNavigator中单击“保存”按钮后,更改将保存到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM