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

GridViewCheckBoxColumn hiding items

1 Answer 215 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 13 Oct 2017, 03:41 PM

I've been banging my head everywhere trying to figure out how to hide values bound to a GridViewComboBox column. 

I'm using ItemsSourceBinding to populate the dropdown with values and then matching up to default values from ItemsSource.  Basically some of the values that are prepopulated from another system like "Approved" or "New" I want to not make those options selectable when the user tries to edit the cell even though they can see them.  

<telerik:RadGridView VerticalAlignment="Stretch" Grid.Row="1" x:Name="PoliciesGridView" ItemsSource="{Binding Policies, Mode=TwoWay}" AutoGenerateColumns="False" DataLoaded="PoliciesGridView_DataLoaded" SelectionMode="Extended" ScrollViewer.VerticalScrollBarVisibility="Visible" CellEditEnded="CellEditEnded" GroupRenderMode="Flat" CanUserDeleteRows="False" Grouped="Grid_Grouped" KeyUp="HandleKeyUpEvent">
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding Command="{Binding EditCommand}" EventName="BeginningEdit" PassEventArgsToCommand="True"/>
</telerik:EventToCommandBehavior.EventBindings>

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CurrentStatus, Mode=TwoWay}" Tag="CurrentStatus" Header="Status" ItemsSourceBinding="{Binding PolicyStatusCodeTable}" DisplayMemberPath="PolicyStatusDsc" SelectedValueMemberPath="PolicyStatusDsc" CellStyleSelector="{StaticResource editedCellStyle }" TextAlignment="Right"/>

I have been successful in setting up an EditCommand to cancel the edit if the Status is Approved thereby making any rows that are Approved read-only as well as reverting the value back to the original value should they choose Approved.  It's a hack  but I feel like there should be a way to just hide those options from the gridviewcombobox so users can't select them.  

 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 18 Oct 2017, 10:55 AM
Hello Victor,

To achieve the desired result, you can use a converter in your ItemsSourceBinding to filter out the undesired values. To display the values correctly in view mode, however, you will need to define a CellTemplate for the column as they will not be selected in the combo box otherwise.

I've attached a sample project to better demonstrate what I have in mind.

If you further need to modify this behavior, you may want to use a normal GridViewDataColumn with both CellTemplate and CellEditTemplate defined.

Please let me know if you find this helpful. If any further questions or concerns arise, do not hesitate to contact me again.

Regards,
Dilyan Traykov
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.
Tags
GridView
Asked by
Victor
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or