110,561
社区成员
发帖
与我相关
我的任务
分享
DataGridViewComboBoxColumn c = new DataGridViewComboBoxColumn();
c.Name = "deName";
c.HeaderText = "数据元名称";
c.Width = 100;
dataGridView.Columns.Insert(2, c);
if (((DataGridViewComboBoxCell)dataGridView.Rows[e.RowIndex].Cells["deName"]).Items.Count > 0)
{
((DataGridViewComboBoxCell)dataGridView.Rows[e.RowIndex].Cells["deName"]).Items.Clear();
}
int a = ((DataGridViewComboBoxCell)dataGridView.Rows[e.RowIndex].Cells["deName"]).Items.Count;
if (a > 0)
{
for (int j = a-1; j >= 0; j--)
{
try
{
MessageBox.Show(a.ToString());
((DataGridViewComboBoxCell)dataGridView.Rows[e.RowIndex].Cells["deName"]).Items.RemoveAt(j);
}
catch(Exception e1)
{
MessageBox.Show(e1.Message);
}
}
}
for (int i = 0; i < list.Count; i++)//取出deid和cname 加入comobox
{
string s = list[i].ToString();
string id = s.Remove(11);//标准id
string name = s.Remove(0, 13);
((DataGridViewComboBoxCell)dataGridView.Rows[e.RowIndex].Cells["deName"]).Items.Add(name);
//hs.Add(name, id);
}
string s1 = list[0].ToString();
string name1 = s1.Remove(0, 13);
((DataGridViewComboBoxCell)dataGridView.Rows[e.RowIndex].Cells["deName"]).Value = name1;//只是显示的效果其实并不是add的001 这个要和第一个值一样!!!