Hello,
I have a RadGridView that uses a GridViewSelectColumn to facilitate row selection. However, under certain circumstances, I would like to prevent certain rows from being selected. Is there any way that I can prevent rows from being selectable?
Thanks,
Mark
I have a RadGridView that uses a GridViewSelectColumn to facilitate row selection. However, under certain circumstances, I would like to prevent certain rows from being selected. Is there any way that I can prevent rows from being selectable?
Thanks,
Mark
3 Answers, 1 is accepted
0
Hi Mark,
Vanya Pavlova
the Telerik team
You may subscribe to the SelectionChanging event of RadGridView and track the CanSelect property from there. Just cancel the event if the row should not be selected.
Vanya Pavlova
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
1
Mark
Top achievements
Rank 1
answered on 06 Feb 2012, 05:23 PM
Hi Vanya,
Thanks for your reply. Yes, that is one solution, but it would still present an enabled checkbox to the user. I was looking for a way to disable the checkbox in the GridViewSelectColumn. So, the solutionI went with was pretty simple in the end - I created a custom column as follows. (Hopefully it might help someone else out there.)
Thanks,
Mark.
Thanks for your reply. Yes, that is one solution, but it would still present an enabled checkbox to the user. I was looking for a way to disable the checkbox in the GridViewSelectColumn. So, the solutionI went with was pretty simple in the end - I created a custom column as follows. (Hopefully it might help someone else out there.)
public
class
CounterSelectionColumn
: GridViewColumn
{
public
CounterSelectionColumn()
{
IsResizable =
false
;
IsReorderable =
false
;
Width = GridViewLength.Auto;
MinWidth = 25;
}
public
override
bool
CanFilter()
{
return
false
;
}
public
override
bool
CanSort()
{
return
false
;
}
public
override
bool
CanGroup()
{
return
false
;
}
public
override
FrameworkElement CreateCellElement(GridViewCell cell,
object
dataItem)
{
if
(cell !=
null
)
{
CheckBox checkBox = cell.Content
as
CheckBox
??
new
CheckBox
{
IsTabStop =
false
,
};
checkBox.SetBinding(UIElement.IsEnabledProperty,
new
Binding(
"IsAvailable"
)
{
Source = dataItem,
Mode = BindingMode.OneWay
});
var row = cell.ParentRow;
if
(row !=
null
)
{
checkBox.SetBinding(ToggleButton.IsCheckedProperty,
new
Binding(
"IsSelected"
)
{
Source = row,
Mode = BindingMode.TwoWay
});
}
return
checkBox;
}
return
base
.CreateCellElement(cell, dataItem);
}
}
Thanks,
Mark.
1
Shreya
Top achievements
Rank 1
answered on 29 Apr 2015, 01:03 PM
Hi Mark,
Thanks a lot your solution worked. Can you tell me how to have a Select all checkbox for this?
Pradeep
commented on 03 Dec 2021, 09:59 AM
Top achievements
Rank 1
Someone please explain how to handle the "Select All" checkbox for this scenario?
On checking the Select All checkbox, only the enabled checkboxes of the grid items should get checked. Disabled ones should remain unchecked.
Please help..
Martin Ivanov
commented on 06 Dec 2021, 01:32 PM
Telerik team
I've prepared a small example showing how to achieve this. The sample uses the IsReadOnlyBinding property of the column, instead of a custom column. I hope that helps.