This is a migrated thread and some comments may be shown as answers.

UWP RadDataGrid: Disable a row

3 Answers 99 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Mohit Singh
Top achievements
Rank 1
Mohit Singh asked on 31 Oct 2017, 06:22 AM

I am developing an UWP application where data is represented in tabular form using RadDataGrid. I want to disable a row depending on a property coming from ItemSource. User will not be able to select disable rows.

Is there any way to add this feature in RadDataGrid.

Any help would be highly appreciated.
Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 02 Nov 2017, 03:52 PM
Hi, Mohit,

The control does not expose such mechanism out of the box, however, you can utilize the SelectionChanged event and check the items within the AddedItems property of the event args. Eventually, you can remove the items based on a property in your business model. For example:

private async void DataGrid_SelectionChanged(object sender, Telerik.UI.Xaml.Controls.Grid.DataGridSelectionChangedEventArgs e)
{
    await Task.Delay(10);
    if (e.AddedItems.Any())
    {
        foreach (Data item in e.AddedItems)
        {
            if (!item.CanBeSelected)
            {
                this.DataGrid.DeselectItem(item);
            }
        }
    }
}

As noticed, some delay is needed for the approach to work. I have attached a sample for your reference.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Cody
Top achievements
Rank 1
answered on 02 Nov 2017, 07:26 PM
Adding to the previous post you can also use the columns CellContentTemplateSelector to change the visual appearance of each column depending on if they are disabled or not. 
0
Stefan Nenchev
Telerik team
answered on 07 Nov 2017, 01:33 PM
Hi, Cody,

Thanks for the follow-up. Indeed, it also seems a good idea to use such template selector and modify the appearance of the items that cannot be selected. 

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataGrid
Asked by
Mohit Singh
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Cody
Top achievements
Rank 1
Share this question
or