SUPERGRID的用法

文章讲述了如何在C#中操作DevExpressGrid控制件,获取特定单元格的值,并在某一列添加下拉框。当选择下拉框的值时,会触发事件更新另一列的内容。问题在于,必须正确绑定`SelectedIndexChanged`事件以避免系统卡死。
摘要由CSDN通过智能技术生成

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;

                }
            }
        }
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值