zoukankan      html  css  js  c++  java
  • 给datagridview的下拉框添加valueChange事件

    修改datagridview的EditMode属性为EdutOnEnter,否则需要点2次以上才出现下拉框

    1.给DataGridView添加EditingControlShowing事件;

    2.编辑EditingControlShowing事件:

    public void dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
      DataGridView dgv = sender as DataGridView;
    
        //判断相应的列
        if (dgv.CurrentCell.GetType().Name == "DataGridViewComboBoxCell" && dgv.CurrentCell.RowIndex != -1)
         {
          //添加下拉事件
          (e.Control as ComboBox).SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);            
         }
    }

    3.定义下拉事件

       public void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
            {
                    ComboBox combox=sender as ComboBox;
    
                     //去掉事件,避免一直触发
                     combox.Leave+=new EventHandler(combox_Leave);
    
                     if (combox.SelectedItem != null)
                     {
                         //添加你需要处理的代码
                     }
            }

    4.添加删除事件

       public void combox_Leave(object sender, EventArgs e)
       {
                ComboBox combox = sender as ComboBox;
                //做完处理撤销动态事件
                combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged);
       }

    来自 https://blog.csdn.net/a312100321/article/details/25195311

  • 相关阅读:
    随笔
    打破生活的套牢
    健忘是种美德
    【转贴】怎样冒充古典高手!
    php数组中删除元素
    JS 总结
    ubuntu apache rewrite
    JS 预览超级大图
    UBUNTU 安装SVN
    Yahoo14条前端优化规则
  • 原文地址:https://www.cnblogs.com/hosseini/p/8649262.html
Copyright © 2011-2022 走看看