zoukankan      html  css  js  c++  java
  • dataGridView添加ComboBox 每行绑定不同的集合,显示默认值

    好了 多说无意,直接上代码,看不看的懂,就看大家的了,解决问题后,可以评论回复,可以一起商讨一些疑难杂症

    List<ProtocolInfo> list = piDB.FindAll().ToList(); //都懂吧
    for (int i = 0; i < list.Count; i++)
    {
        List<string> tempList = new List<string>(GetDirFiles(list[i].name)).Select(a => Path.GetFileName(a)).ToList();    ///获取 需要显示的集合(可不用理会)
        this.Invoke(new MethodInvoker(() =>
        {
            int index = this.skinDataGridView1.Rows.Add();     //添加新行 
            this.skinDataGridView1.Rows[index].Cells[0].Value = list[i].id;   //第一个单元格赋值
            this.skinDataGridView1.Rows[index].Cells[1].Value = list[i].name;  //第二个单元格赋值
            this.skinDataGridView1.Rows[index].Cells[2].Value = list[i].port;  //第三个单元格赋值
            this.skinDataGridView1.Rows[index].Cells[3].Value = list[i].help; //  第四个单元格赋值
            this.skinDataGridView1.Rows[index].Cells[4].Value = false; //  第五个 checkbox 复制 
            for (int ii = 5; ii < skinDataGridView1.ColumnCount; ii++)
            {
                DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();      //声明一个 配置项
                dataGridViewCellStyle1.NullValue = "需要显示的默认值";          //为空值时需要显示的值 
    
                DataGridViewComboBoxCell dgCell = new DataGridViewComboBoxCell();
                dgCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                dgCell.Items.AddRange(tempList.Where(a => a.Substring(0, 1) == (ii - 4).ToString()).ToArray());
    
                dgCell.Style = dataGridViewCellStyle1;
    
    
                this.skinDataGridView1.Rows[index].Cells[ii] = dgCell;
    
            }
    
        }));
    }
  • 相关阅读:
    2. 商城项目完整购物链路 lq
    如何看源码? lq
    事务的了解 lq
    1. 商城业务架构分析 lq
    并发的基础知识 lq
    mysql 索引 lq
    mysqlinnodb了解 lq
    IE6.0、IE7.0 与FireFox CSS兼容的解决方法
    CSS:html/css教程:背景图片的定位问题详解
    IE6 BUG
  • 原文地址:https://www.cnblogs.com/qc-id-01/p/10949617.html
Copyright © 2011-2022 走看看