如果,时间长时了,已前做过的东西,都记不得了,所以记录一下。
废话不多说。
1、拖出gridview控件,然后将字段绑定上去
2、将要做下拉框的控件加入RepositoryItemImageComboBox控件
3、绑定数据
for (int i = 0; i < 3; i++) { //如果取值时,数据源中会是Value repositoryItemImageComboBox1.Items.Add( new DevExpress.XtraEditors.Controls.ImageComboBoxItem() { Description = "Test"+i, Value = i.ToString()//只能字符串 }); } DataTable dt = new DataTable(); dt.Columns.Add("C", System.Type.GetType("System.Boolean")); dt.Columns.Add("D", System.Type.GetType("System.String")); dt.Columns.Add("E", System.Type.GetType("System.Boolean")); dt.Columns.Add("F", System.Type.GetType("System.String")); dt.Columns.Add("G", System.Type.GetType("System.String")); DataRow row = dt.NewRow(); row["C"] = true; row["D"] = "1"; row["E"] = true; row["F"] = "TestF"; row["G"] = "删除"; dt.Rows.Add(row); DataRow row1 = dt.NewRow(); row1["C"] = false; row1["D"] = "2"; row1["E"] = false; row1["F"] = "TestF1"; row1["G"] = "删除"; dt.Rows.Add(row1); gridControl1.DataSource = dt;
4、初始时绑定要选中值
private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) { if (e.Column.Name == "D" && e.RowHandle >= 0) { ImageComboBoxEdit edit1 = new ImageComboBoxEdit(); edit1.Properties.Items.AddRange(repositoryItemImageComboBox1.Items); e.RepositoryItem = edit1.Properties; foreach (ImageComboBoxItem item in edit1.Properties.Items) { if (gridView1.GetRowCellValue(e.RowHandle, "D").ToString() == item.Value.ToString()) { edit1.SelectedItem = item; } } } }