原创文章,转载请注明出处!
界面布局:点击“添加”按钮,会读取相关文件,将文件相关信息作为新的一行添加到DataGridView,此时动态绑定DataGridViewComboBoxCell不同的下拉选项。代码如下:
1 //新建一行
2 DataGridViewRow dr = new DataGridViewRow();
3 dr.CreateCells(dataGridView1);
4
5 dr.Cells[0].Value = pFeatureClass.AliasName;
6 dataGridView1.Rows.Insert(0, dr);//添加新行
7 DataGridViewComboBoxCell dgvComboTop = dr.Cells[1] as DataGridViewComboBoxCell;//将Cell转换成ComboBoxCell
8 DataGridViewComboBoxCell dgvComboBottom = dr.Cells[2] as DataGridViewComboBoxCell;
9
10 IField pField = null;
11 IFields pFields = pFeatureClass.Fields;
12 for (int i = 0; i < pFields.FieldCount - 1;i++ )
13 {
14 pField = pFields.get_Field(i);
15 if (pField.Type!=esriFieldType.esriFieldTypeGeometry)
16 {
17 dgvComboTop.Items.Add(pField.Name);
18 dgvComboBottom.Items.Add(pField.Name);
19 }
20 }