zoukankan      html  css  js  c++  java
  • 在datagridview里添加自定义控件列

    1、定义一个控件如:commbox

      

    1. //定义下拉列表框、隐藏控件、在datagridview中添加控件  
    2.        private ComboBox datacmb=new ComboBox();  
    3.       datacmb.Visible = false;  
    4.       this.dataGridView1.Controls.Add(datacmb);  

    2、添加datagridview的CurrentCellChanged事件

      

    1. private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)  
    2.         {  
    3.             try  
    4.             {  
    5.                 if (this.dataGridView1.CurrentCell.ColumnIndex == 4)  
    6.                 {  
    7.                     Rectangle rec = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, false);  
    8.                     datacmb.Left = rec.Left;  
    9.                     datacmb.Top = rec.Top;  
    10.                     datacmb.Width = rec.Width;  
    11.                     datacmb.Height = rec.Height;  
    12.                     datacmb.Visible = true;                    
    13.                 }  
    14.                 else  
    15.                 {  
    16.                     datacmb.Visible = false;  
    17.                 }  
    18.             }  
    19.             catch  
    20.             {  
    21.                 //MessageBox.Show(ex.Message);  
    22.             }  
    23.         }  
     
    参考资料:

    -------------------------------------------------------------------------------------------------------------------------------------------------
    数据库优化
    数据库教程
    数据库实战经验分享博客

    百度云下载

    评测


  • 相关阅读:
    移动端适配方案总结
    排序算法
    使用onchange依赖监控文件修改失效
    实现一个可拖拽的div
    在vue中实现两个输入框内容的同步及转换
    简易loading动画的制作
    了解MVC
    Spring Boot使用模板引擎总结
    在配置好log4j后信息log还是在Console中输出
    运行时报java.sql.SQLException: No suitable driver的几种解决办法
  • 原文地址:https://www.cnblogs.com/longle/p/datagridview.html
Copyright © 2011-2022 走看看