• 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;
    
            }
    
        }));
    }
  • 相关阅读:
    Link assemblies causes app crashes if you have an EditText
    Link causes xamarin Android binding library project to crash
    Linux系统目录结构详解
    Centos Linux系统优化二
    Centos Linux系统优化一
    rm命令详解
    mv命令详解
    cp命令详解
    echo命令详解
    touch命令详解
  • 原文地址:https://www.cnblogs.com/qc-id-01/p/10949617.html
Copyright © 2020-2023  润新知