2012-07-17 65 views
0

对于产品有1个datagridview,对于类别有1个组合框,我已将组合框的选定值设置为CategoryID。具有选定值和自动完成功能的组合框

当我在组合框中键入类别名称的第一个字母,然后按下输入名称在组合框内完成,但datagridview中的相关字段不会更改,直到我单击组合外。

请问有没有办法让按Enter键在datagridview中执行更改,以便我可以直接在保存按钮单击时保存修改。

+0

你如何将你的类别绑定到组合框并更新gridview?我今天做了同样的事情,它工作 – codingbiz 2012-07-17 22:36:10

+0

@tcoder,我通过databindingsource和databindingNavigator将产品(datagrid)和数据绑定源分类(组合)使用L2SQL。所有工作都很好,但在将数据保存到数据库(保存bindingSourceNavigator的按钮)之前,无法使用“Enter”键同时更新两者。 – 2012-07-17 23:39:44

+0

我实际上有一个中心方法'fillGrid()',可以从任何点调用,但我没有使用bindingsource。在fillGrid中,我只有'mygridview.DataSource = MyClass.GetSomeData()' – codingbiz 2012-07-17 23:54:57

回答

0

我可以simultanuously在按下“Enter”键连击自动完成关键,通过下一个事件更新产品的BindingSource中的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; 
    } 
} 

点击保存按钮在bindingsourceNavigator更改保存到数据库后。

1

这样在GridView可以从任何来源通过调用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 
    } 
+0

在这种情况下,我们不使用组合过滤datagrid行,仅使用组合在产品表中更改类别。 – 2012-07-18 10:32:00

相关问题