private void grdRole_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (IsANonHeaderButtonCell(e)) { string userId = BaseInterfaceLogic.GetDataGridViewEntityId(this.grdRole, BaseUserEntity.FieldId); if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(this.TargetPermissionId)) { FrmRolePermissionScope frmRolePermissionScope = new FrmRolePermissionScope(userId, this.PermissionItemScopeCode); frmRolePermissionScope.ShowDialog(this); } } // 保证只能勾选一个 else if (this.grdRole.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewCheckBoxCell) { Boolean bl = Convert.ToBoolean(this.grdRole.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue); if (bl) { for (int i = 0; i < e.ColumnIndex; i++) { if (this.grdRole.Rows[e.RowIndex].Cells[i] is DataGridViewCheckBoxCell) { this.grdRole.Rows[e.RowIndex].Cells[i].Value = !bl; } } this.grdRole.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = bl; for (int i = e.ColumnIndex + 1; i < grdRole.ColumnCount; i++) { if (this.grdRole.Rows[e.RowIndex].Cells[i] is DataGridViewCheckBoxCell) { this.grdRole.Rows[e.RowIndex].Cells[i].Value = !bl; } } } } }
private void grdRole_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (IsANonHeaderButtonCell(e)) { string userId = BaseInterfaceLogic.GetDataGridViewEntityId(this.grdRole, BaseUserEntity.FieldId); if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(this.TargetPermissionId)) { FrmRolePermissionScope frmRolePermissionScope = new FrmRolePermissionScope(userId, this.PermissionItemScopeCode); frmRolePermissionScope.ShowDialog(this); } } // 保证只能勾选一个 else if (this.grdRole.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewCheckBoxCell) { Boolean bl = Convert.ToBoolean(this.grdRole.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue); if (bl) { for (int i = 0; i < e.ColumnIndex; i++) { if (this.grdRole.Rows[e.RowIndex].Cells[i] is DataGridViewCheckBoxCell) { this.grdRole.Rows[e.RowIndex].Cells[i].Value = !bl; } } this.grdRole.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = bl; for (int i = e.ColumnIndex + 1; i < grdRole.ColumnCount; i++) { if (this.grdRole.Rows[e.RowIndex].Cells[i] is DataGridViewCheckBoxCell) { this.grdRole.Rows[e.RowIndex].Cells[i].Value = !bl; } } } } }