1.获取grid某个单元格的值
for (int r = grdImporter.RowsCount - 1; r >= 1; r--)
{
SuperGrid.Grid.GridRow row = grdImporter.Rows[r];
string returnson = row[grdImporter.Columns[11]].Value == null ? "" : row[grdImporter.Columns[11]].Value.ToString();
if (returnson != null)
{
if (row[grdImporter.Columns[12]].Value == null || row[grdImporter.Columns[13]].Value == null || row[grdImporter.Columns[14]].Value == null)
{
MessageBox.Show("返工原因不为空时,来源依据/责任人/责任部门 必填!");
grdImporter.Rows.Remove(r);--移除grid的行数据
return;
}
}
2. private DevExpress.XtraGrid.Views.Grid.GridView 的某一列添加下拉框,当点击下拉框的时候触发事件:选择列A的值,列B的值也随之改变
(1)给列添加下拉框:
去图形设计界面的columnedit选择已经建好的comboxedit
(2)添加触发事件
在load的函数里,添加这句话
gridView2.CustomRowCellEdit += GridView_CustomRowCellEdit;
private void GridView_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
if (e.Column.VisibleIndex == 3) // 第一列的索引为 0
{
RepositoryItemComboBox comboBoxEdit = e.RepositoryItem as RepositoryItemComboBox;
if (comboBoxEdit != null)
{
comboBoxEdit.SelectedIndexChanged -= ComboBoxEdit_SelectedIndexChanged;
//这里有个问题,如果不加上面这句,系统只能执行一次,第二次就会卡死。
为什么?
comboBoxEdit.SelectedIndexChanged += ComboBoxEdit_SelectedIndexChanged;
}
}
}
private void ComboBoxEdit_SelectedIndexChanged(object sender, EventArgs e)
{
DevExpress.XtraEditors.ComboBoxEdit comboBox = sender as DevExpress.XtraEditors.ComboBoxEdit;
if (comboBox != null)
{
string selectedValue = comboBox.EditValue.ToString();
this.CmbProblemType.Items.Clear();
// 使用选择的值进行进一步的操作
DataTable dt1 = this.Facade.GetParameterCode("质量积分判定_问题类别", selectedValue);
if (dt1 != null)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
ItemObject item = new ItemObject();
item.ItemValue = dt1.Rows[i]["paramcode"].ToString();
item.ItemText = dt1.Rows[i]["paramdesc"].ToString();
this.CmbProblemType.Items.Add(item);
}
}
else
{
this.ShowErrorMessage("未维护!");
return;
}
}
}