若是,時間長時了,已前作過的東西,都記不得了,因此記錄一下。spa
廢話很少說。code
一、拖出gridview控件,而後將字段綁定上去blog
二、將要作下拉框的控件加入RepositoryItemImageComboBox控件ip
三、綁定數據字符串
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;
四、初始時綁定要選中值it
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; } } } }