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 设置与否 都不影响结果。
方法二:
#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 本文版权归作者和CSDN共同拥有,欢迎转载,但是,如果没有从本节宣布提交权限必须保留,并连接到原来的文章页给出视在位置。