在winform中:
需求:我现在用DataGridView显示一组数据,其中有一列想显示为combox,combox的数据源用枚举提供。
问题:在显示的时候,combox这一列老是显示不出来。不知道为什么。
下面是combox的数据源:
 private DataTable GetComBoxDataSource()
        {
            DataTable dt = new DataTable();            dt.Columns.Add(new DataColumn( "Text", typeof (string)));
            dt.Columns.Add(new DataColumn("Values", typeof(string)));            string[] enumns = Enum.GetNames(typeof (ZCTTDataType));            for (int i = 0; i < enumns.Length;i++ )
            {
                DataRow row = dt.NewRow();                switch (enumns[i])
                {
                    case "dateTime":
                        row["Text"] = "dateTime";
                        row["Values"] = "dateTime";
                        break;
                    case "unsignedShort":
                        row["Text"] = "unsignedShort";
                        row["Values"] = "Values";
                        break;
                    case "ZCTTint":
                        row["Text"] = "int";
                        row["Values"] = "ZCTTint";
                        break;
                    case "unsignedByte":
                        row["Text"] = "unsignedByte";
                        row["Values"] = "unsignedByte";
                        break;
                    case "ZCTTstring":
                        row["Text"] = "string";
                        row["Values"] = "ZCTTstring";
                        break;
                    case "ZCTTlong":
                        row["Text"] = "long";
                        row["Values"] = "ZCTTlong";
                        break;
                    case "binary":
                        row["Text"] = "binary";
                        row["Values"] = "binary";
                        break;
                    default:
                        break;
                }
                dt.Rows.Add(row);
            }
            return dt;
        }在加载的时候,datagirdview的显示是下面的代码:
//显示数据                SetSettingGridViewDisplay();                bindingSource.DataSource = itemAttributeDataTable;
                this.GV_ColumnInfo.DataSource = bindingSource;                DataGridViewColumn fieldNameColumn = new DataGridViewTextBoxColumn();
                fieldNameColumn.HeaderText = "field_name";
                fieldNameColumn.DataPropertyName = "field-name";
                this.GV_ColumnInfo.Columns.Add(fieldNameColumn);                DataGridViewColumn idColumn = new DataGridViewTextBoxColumn();
                idColumn.HeaderText = "id";
                idColumn.DataPropertyName = "id";
                this.GV_ColumnInfo.Columns.Add(idColumn);                DataGridViewColumn identifierColumn = new DataGridViewTextBoxColumn();
                identifierColumn.HeaderText = "identifier";
                identifierColumn.DataPropertyName = "identifier";
                this.GV_ColumnInfo.Columns.Add(identifierColumn);                DataGridViewComboBoxColumn typeColumn = new DataGridViewComboBoxColumn();
                typeColumn.DataSource = GetComBoxDataSource();
                typeColumn.Width = 100;
                typeColumn.DataPropertyName = "type";
                typeColumn.DisplayMember = "Text";
                typeColumn.ValueMember = "Values";
                typeColumn.HeaderText = "type";