dev gridcontrol 单选框效果

  private void gridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //此处4是单选框所在的列号
            if (e.Column.ColumnHandle != 4)
            { 
                return;
            }
            for (int i = 0; i < gridView1.DataRowCount; i++)
            {
                //非当前行 置为 未选中状态
                if (i != e.RowHandle)
                { 
                    //0表示 未选中
                    gridView1.GetDataRow(i)[e.Column.ColumnHandle] = "0";
                }
            }
        }


此时gridView1 .OptionsSelection.MultiSelect 设置与否 都不影响结果。


dev gridcontrol 单选框效果

方法二:

  #region gridView1_RowCellClick事件
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Button == MouseButtons.Left) // 判断是否是用鼠标点击  
            {
                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo ghi = gridView1.CalcHitInfo(new Point(e.X, e.Y));
                if (ghi.InRow)  // 判断光标是否在行内  
                {
                    //清空勾选项
                    for (int i = 0; i < gridView1.DataRowCount; i++)
                    {
                        if (gridView1.FocusedRowHandle != i)
                        {
                            gridView1.GetDataRow(i)["selected"] = false;
                        }
                    }
                    if ((bool)gridView1.GetDataRow(ghi.RowHandle)["selected"] == true)
                    {
                        gridView1.GetDataRow(e.RowHandle)["selected"] = false;
                    }
                    else
                    {
                        gridView1.GetDataRow(e.RowHandle)["selected"] = true;
                    }
                }
            }
        }
        #endregion
  #region  单选框控制
        private void gridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.ColumnHandle != 0)
            {
                return;
            }
            for (int i = 0; i < gridView1.DataRowCount; i++)
            {
                //非当前行 置为 未选中状态  
                if (i != e.RowHandle)
                {
                    //0表示 未选中  
                    gridView1.GetDataRow(i)[e.Column.ColumnHandle] = "0";
                }
            }
        }
        #endregion


作者:jiankunking 出处:http://blog.csdn.net/jiankunking

上一篇:Convex 何以超越 MakerDAO 跃居第二大项目? | Footprint Analytics


下一篇:Android仿WIN8系统磁贴点击下沉倾斜效果