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

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;

        }

    }));
}

 

相关文章:

  • 2022-12-23
  • 2022-01-25
  • 2021-09-02
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-02-23
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2021-12-03
相关资源
相似解决方案