如何在DataGridView组合框中使用选定的索引更改事件 [英] how to use selected index change event in DataGridView combobox

查看:139
本文介绍了如何在DataGridView组合框中使用选定的索引更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在DataGridView组合框中使用选定的索引更改事件

how to use selected index change event in DataGridView combobox

推荐答案

您需要为datagridview处理两个事件

在datagridview的EditingControlShowing中,并在事件处理程序中附加事件处理程序,以更改组合框的selectedIndex

You need to handle two events for the datagridview

EditingControlShowing of the datagridview and in the eventhandler attach the eventhandler for selectedindexchanged of the combobox

this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(OnEditControlShowing);







void OnEditControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control is ComboBox)
            {
                ((ComboBox)e.Control).SelectedIndexChanged += new EventHandler(OnSelectIndexChanged);
            }
        }


goooooooooooood,但是像这样的代码
goooooooooooood but like this code
if (e.Control is ComboBox)
               {
                   ((ComboBox)e.Control).SelectedIndexChanged += new System.EventHandler(this.onseleteddatagridomboboxevent);
               }









private void onseleteddatagridomboboxevent(object sender, EventArgs e)
        {

                try
                {
                    string test = grd_setter.Rows[0].Cells["c2"].Value.ToString();
                         DataTable dt = pDAL.Get_Data("select  Date from tbl_packet where PNo='" + test.ToString() + "'");
                          d = dt.Rows[0][0].ToString();
                          grd_setter.Rows[0].Cells["c3"].Value = d.ToString();
                }
                catch { }
        }


这篇关于如何在DataGridView组合框中使用选定的索引更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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