dataGridView添加ComboBox 每行绑定不同的集合,显示默认值

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

List<ProtocolInfo> list = piDB.FindAll().ToList(); //都懂吧
for (int i = ; 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[].Value = list[i].id; //第一个单元格赋值
this.skinDataGridView1.Rows[index].Cells[].Value = list[i].name; //第二个单元格赋值
this.skinDataGridView1.Rows[index].Cells[].Value = list[i].port; //第三个单元格赋值
this.skinDataGridView1.Rows[index].Cells[].Value = list[i].help; // 第四个单元格赋值
this.skinDataGridView1.Rows[index].Cells[].Value = false; // 第五个 checkbox 复制
for (int ii = ; 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(, ) == (ii - ).ToString()).ToArray()); dgCell.Style = dataGridViewCellStyle1; this.skinDataGridView1.Rows[index].Cells[ii] = dgCell; } }));
}
上一篇:python3--删除所有空目录,第一个有实际用处的程序


下一篇:ajax--参数默认值问题