Disable rows in grid based on a collection

1 Answer 153 Views
GridView
alex
Top achievements
Rank 2
Bronze
Iron
Iron
alex asked on 12 Feb 2022, 07:15 PM | edited on 22 Oct 2022, 07:53 PM

I have a RadGridView bound to an Obersvable Collection of an object with ID and Name. After closing the window, I save the selected IDs in an list. When the user reopens the form to select more items, I want to show all the items but disable the rows based on the IDs that were previously selected (those on the IDs list).

How can I achieve that?

 

I think that the best solution is a behavior and not a style, but I don't know how to do it.

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 07 Sep 2022, 07:42 PM

Hi, I am still waiting. Do you have some demo project with a similar behavior?
Martin Ivanov
Telerik team
commented on 12 Sep 2022, 10:10 AM

I am not sure what do you mean by disabling the IDs. Do you want to disable the previously selected rows? If so, you can make them read-only. To do so, you can create a new bool property in your row's model and data bind it to the columns using the IsReadOnlyBinding property as shown here: https://docs.telerik.com/devtools/wpf/controls/radgridview/columns/how-to/read-only-rows-cells

With this setup, you can set the property of the rows' data items when you re-open the form in order to make them read-only. 

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 28 Oct 2022, 05:46 AM

I can't add properties for UI. I was thinking of comparing values from one list (list of selected IDs) to the IDs column. If the value exists on the first list, I know that the value is selected previoulsy and the row should ne grayed out. Maybe you have an attached property for that?
Martin Ivanov
Telerik team
commented on 28 Oct 2022, 10:05 AM

Thank you for the additional information. I have added a new answer that describe one way to get the desired result. I hope that helps.

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 28 Oct 2022, 10:05 AM

Hello Alex,

To achieve your requirement, you can use the IsEnabled property of the GridViewRow elements. In case you can't include additional properties to support this state in the data items, you can use a helper collection and a converter. This will allow you to data bind the IsEnabled property to the Id of the data item and compare it against the collection with the previous selected items.

You can see this approach in the attached project. I hope this is useful.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
alex
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or