Devexpress GridControl中combobox级联显示
1、combobox控件的创建,我是在CustomRowCellEditForEditing这个事件下处理的。(因为我所需要显示co罪焐芡拂mbobox的列是动态创建的,所以需要这样创建,如果你是固定显示,直接绑定combobox点击事件就可以了。)在这个事件里面,还可以控制某一列不同行显示不同控件。(因为Devexpress是只能设置某一列控件的属性的,不能精准到控制每个单元格中的控件) private void gvwFetchData_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) { DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView; RepositoryItemComboBox cbx = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox(); switch (e.Column.FieldName) { //case "DBConstructionID": //cbx.Items.Clear(); // cbx.Items.AddRange(cbxConstructions.Select(c => new Models.ComboBoxItemTextValue<int>(c.FieldID, c.FieldName)).ToList()); // cbx.SelectedValueChanged += new EventHandler(cbx_SelectedValueChanged); // //e.RepositoryItem = cbx; // gclDataOperate.RepositoryItems.Add(cbx); // gvwFetchData.Columns["ConstructionName"].ColumnEdit = cbx; //break; case "BuildingName": //获取该行楼盘id string constructid = gvwFetchData.GetRowCellValue(e.RowHandle, "DBConstructionID").ToString(); //楼栋 //根据楼盘查询楼栋的数据 IList<BLL.RealDataWeb.ComboBoxField> cbxBuildings = matchData.GetBuilding(iCityID, Convert.ToInt32(constructid)); //给该行楼栋combobox绑定数据源 cbx.Items.Clear(); cbx.Items.AddRange(cbxBuildings.Select(b => new Models.ComboBoxItemTextValue<int>(b.FieldID, b.FieldName)).ToList()); //combobox值改变后触发 cbx.SelectedValueChanged += new EventHandler(cbx_SelectedValueChanged); //下拉框选中值后,需要进行转换 cbx.ParseEditValue += new ConvertEditValueEventHandler(cbx_ParseEditValue); //指定该列控件 e.RepositoryItem = cbx; break; case "HouseName": string BuindId = gvwFetchData.GetRowCellValue(e.RowHandle, "DBBuildingID").ToString(); //房号 IList<BLL.RealDataWeb.ComboBoxField> House = matchData.GetHouse(iCityID, Convert.ToInt32(BuindId)); cbx.Items.Clear(); cbx.Items.AddRange(House.Select(h => new Models.ComboBoxItemTextValue<int>(h.FieldID, h.FieldName)).ToList()); cbx.SelectedValueChanged += new EventHandler(cbx_SelectedValueChanged); cbx.ParseEditValue += new ConvertEditValueEventHandler(cbx_ParseEditValue); e.RepositoryItem = cbx; break; default: break; } }


3、 //grid中的下拉框必须要处理一下,不然会报(对象必须实现iconvertible)错误 private void cbx_ParseEditValue(object sender, ConvertEditValueEventArgs e) { e.Value = e.Value.ToString(); e.Handled = true; }