下拉值更改时立即更新datagird [英] update datagird imediatly when dropdown value changes

查看:102
本文介绍了下拉值更改时立即更新datagird的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在Windows窗体应用程序上工作,我的数据网格中有一个组合框.现在,当组合框中的值更改时,如何立即更新数据网格中的记录.

Hi,

i''m working on a windows forms applicaion, i have a combo box in my datagrid. now how to update records in data grid immediatly when the value in the combo box got changed.

推荐答案



有时,了解用户何时在ComboBox编辑控件中选择了一个项目会很有帮助.在窗体上使用ComboBox时,通常可以处理SelectedIndexChanged事件.使用DataGridViewComboBox,您可以通过使用DataGridView.EditingControlShowing事件来执行相同的操作.下面的代码示例演示如何执行此操作.请注意,该示例还演示了如何防止触发多个SelectedIndexChanged事件.
Hi,

Sometimes it is helpful to know when a user has selected an item in the ComboBox editing control. With a ComboBox on your form you would normally handle the SelectedIndexChanged event. With the DataGridViewComboBox you can do the same thing by using the DataGridView.EditingControlShowing event. The following code example demonstrates how to do this. Note that the sample also demonstrates how to keep multiple SelectedIndexChanged events from firing.
private void dataGridView1_EditingControlShowing(object sender, 
                    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox cb = e.Control as ComboBox;
    if (cb != null)
    {
        // first remove event handler to keep from attaching multiple:
        cb.SelectedIndexChanged -= new
        EventHandler(cb_SelectedIndexChanged);

        // now attach the event handler
        cb.SelectedIndexChanged += new 
        EventHandler(cb_SelectedIndexChanged);
    }
}

void cb_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index changed");
}



祝你好运
快乐的编码:)



Best Luck
happy Coding:)


这篇关于下拉值更改时立即更新datagird的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆