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

Disabling rows of Gridview on right click of row

4 Answers 235 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Babitha
Top achievements
Rank 1
Babitha asked on 06 Jun 2018, 05:27 AM

Hi,

I am working on a project where I have a requirement to disable the row on the right click of row. I could implement functions add, edit, delete by using context menu. Is there any way where I can add disable row to the context menu and clicking on the option will disable the row?

4 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 08 Jun 2018, 08:12 AM
Hi Babitha,

Implementing the menu itself should be the easier task. You can follow this article that describes how to add context menu to RadGridView. Then add a "disable" menu item and handle it separately according to the menu item text. You can access the clicked row, using the GetClickedElement<GridViewRow> and the set the IsEnabled value based on the business logic of its item (row.DataContext).
However, the more difficult part of the task comes with the need to keep the IsEnabled state between the virtualized items. By default RadGridView uses row virtualization with container recycling. In this way a row container that is used to display an item will be reused to display another item, when the former one falls out of the viewport. Having this in mind, directly modifying row properties based on item business logic is not a good idea, as the disabled row can be used to display an item that should not be disabled. So, I believe that there are to valid approaches to this task. The first one is to use the RowLoaded/RowUnloaded events, which are raised every time a new row is brought in the viewport. Then you can check whether the underlying row should be disabled or not. The other approach relies on data binding. You can bind GridViewRow's IsEnabled property to a property of the item type. Then, when clicking the menu item, the item's property needs to be modified and the WPF data binding mechanism will do the work. Please do not hesitate to contact us for additional guidelines if you encounter any difficulties with the implementation.

Regards,
Ivan Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Babitha
Top achievements
Rank 1
answered on 11 Jun 2018, 10:47 AM

Hi Ivan,

Is it possible to provide a sample of how it works? I am new to telerik as well as wpf. Thanks in advance.

0
Accepted
Stefan
Telerik team
answered on 14 Jun 2018, 08:30 AM
Hello Babitha,

Attached to my reply you can find an example that demonstrates the approach regarding the data binding suggested by my colleague. For this purpose I have used the RadContextMenu for RadGridView SDK Example. It can be reviewed through the SDK Samples Browser. I have modified the demo by adding an IsEnabled boolean property to the business model. Then, it is bound to the IsEnabled property of GridViewRow through a Style.

I hope this helps.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Babitha
Top achievements
Rank 1
answered on 15 Jun 2018, 05:56 PM
Thank you Stefan.
Tags
GridView
Asked by
Babitha
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Babitha
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or