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

Enable/disable cell RadComboBox

4 Answers 287 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 23 Apr 2010, 01:54 PM
Hi, I have a RadGridView and one of the columns has a CellTemplate with a TextBlock and a CellEditTemplate with a RadComboBox.  The RadGridView ItemSource is a collection of business objects.  I'd like it so that the RadComboBox is only accessible based on a property on the business object (in other words you can only choose a different item in the list if the business object is editable).  It seems that you can't use a binding in the GridViewDataColumn IsReadOnly property (it only accepts True/False), so I was wondering what the best way to do this would be?

Here's my code:

<gridview:RadGridView AutoGenerateColumns="False" 
        ShowGroupPanel="False" Margin="4" RowIndicatorVisibility="Collapsed" Grid.Column="0" 
        Grid.Row="1" Background="White" ItemsSource="{Binding BusinessObjects}"
    <gridview:RadGridView.Columns> 
        <gridview:GridViewDataColumn Width="auto" Header="Columns" IsFilterable="False" 
                IsSortable="False" IsReadOnly="True" > 
            <gridview:GridViewDataColumn.CellTemplate> 
                <DataTemplate> 
                    <TextBlock Text="{Binding SelectedOne.Label}" /> 
                </DataTemplate> 
            </gridview:GridViewDataColumn.CellTemplate> 
            <gridview:GridViewDataColumn.CellEditTemplate> 
                <DataTemplate> 
                    <input:RadComboBox IsReadOnly="{Binding IsReadOnly}" IsEditable="{Binding IsEditable}" IsTextSearchEnabled="False" 
                            OpenDropDownOnFocus="True" KeyDown="RadComboBox_KeyDown" 
                            MinWidth="100"  
                            ItemsSource="{Binding Source={StaticResource ViewModel}, Path=SearchList}" 
                            DisplayMemberPath="Label" 
                            Text="{Binding Source={StaticResource ViewModel}, Path=SearchText, Mode=TwoWay}" 
                            SelectedItem="{Binding SelectedOne}" 
                            attachedcommands:TelerikSelectorSelectionChanged.Command="{Binding Source={StaticResource ViewModel}, Path=SelectionChangedCommand}" 
                            attachedcommands:TelerikSelectorSelectionChanged.CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=SelectedValue}" /> 
                </DataTemplate> 
            </gridview:GridViewDataColumn.CellEditTemplate> 
        </gridview:GridViewDataColumn> 
    </gridview:RadGridView.Columns> 
</gridview:RadGridView> 

Thanks,
Tom

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 Apr 2010, 08:16 AM
Hello Tom,

If this is Silverlight 4 you can bind the column IsReadOnly as well. Alternatively you can use CellEditTemplateSelector column property to provide different CellEditTemplate based on your condition.

Sincerely yours,
Vlad
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Tom
Top achievements
Rank 1
answered on 26 Apr 2010, 12:17 PM
Thanks for your response Vlad.  I saw your blog post here: http://blogs.telerik.com/blogs/posts/10-04-01/conditional_styles_and_templates_with_radgridview_for_silverlight_and_wpf.aspx

However what I need to do is include references to my viewmodel (e.g. through StaticResource) in the fragment of Xaml that I'm supplying as the CellEditTemplate, for example the ItemSource on the RadComboBox in the template as in the code above.  Is this even possible?  I've read a few articles on MSDN and it looks like the XamlReader.Load method creates a tree in a separate namescope so I'm not sure how these references are going to work..?

For example if I use the following:

template = (DataTemplate)XamlReader.Load(@"
    <DataTemplate 
        xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" 
        xmlns:input=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
        xmlns:attachedcommands=""clr-namespace:...Presentation.Modules.Common.Commands;assembly=...Presentation.Modules.Common""> 
    <input:RadComboBox IsEditable=""True"
                IsTextSearchEnabled=""False"" OpenDropDownOnFocus=""True"
                MinWidth=""100"
                ItemsSource=""{Binding Source={StaticResource ViewModel}, Path=ParentMappingSearchList}"
                DisplayMemberPath=""Label"
                Text=""{Binding Source={StaticResource ViewModel}, Path=ParentMappingSearchText, Mode=TwoWay}"
                SelectedItem=""{Binding ParentMapping}"
                attachedcommands:TelerikSelectorSelectionChanged.Command=""{Binding Source={StaticResource ViewModel}, Path=ParentMappingSelectionChangedCommand}"
                attachedcommands:TelerikSelectorSelectionChanged.CommandParameter=""{Binding RelativeSource={RelativeSource Self}, Path=SelectedValue}""/> 
    </DataTemplate> 
"); 

I get BindingExpression path error: 'ParentMappingSearchList' property not found on [the object that represents the row in the grid]..

Thanks,
Tom
0
Vlad
Telerik team
answered on 26 Apr 2010, 12:22 PM
Hi Tom,

You can declare desired template in XAML instead (for example in Resources) XamlReader.Load().

Greetings,
Vlad
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Tom
Top achievements
Rank 1
answered on 27 Apr 2010, 10:47 AM
Thanks Vlad, got this working with a DataTemplate defined in the Resources of my main XAML.  Wasn't sure how to get a reference to this resource from inside the SelectTemplate method of the MappingParentTemplateSelector class though.. Ended up setting a static reference to the view object in the view constructor..

public partial class MyView // XAML code behind 
    public MyView() 
    { 
        InitializeComponent(); 
        View = this
    } 
 
    public static MyView View; 
 
public class MappingParentTemplateSelector : DataTemplateSelector 
    public override DataTemplate SelectTemplate(object item, DependencyObject container) 
    { 
        var mapping = (Mapping)item; 
 
        if (mapping.IsMappingEditable) 
        { 
            return (DataTemplate)(MyView.View.Resources["MappingParentEditTemplate"]); 
        } 
 
        return (DataTemplate)(MyView.View.Resources["MappingParentTemplate"]); 
    } 

Thanks,
Tom

Tags
GridView
Asked by
Tom
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Tom
Top achievements
Rank 1
Share this question
or