Disabled field value changes on Keypress

4 posts, 0 answers
  1. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 30 Jun 2015 Link to this post

    I have 2 templates in my TreeListView.  One for display and one for edit as shown below.  When I select a node that is in display mode then use the keyboard and type a key, the "Name" value is updated with that key press.  On key press, the edit template is loaded and the Name/Description fields are disabled.  The IsEditableStatus field is not changed.  This makes no sense and I don't know how to get around it.  Thanks for your help.

     The TreeListView:

    <telerik:RadTreeListView
                        x:Name="treeListView"
                        AutoGenerateColumns="False"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        CanUserFreezeColumns="False"
                        CanUserReorderColumns="False"
                        SelectionMode="Single"
                        Grid.Row="1"
                        Margin="5"
                        IsReadOnly="{Binding IsReadOnly}"
                        ItemsSource="{Binding Hierarchy, Mode=TwoWay}"
                        SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                        IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
                        AutoExpandItems="True"
                        ShowGroupPanel="False"
                        IsFilteringAllowed="False"
                        ShowColumnHeaders="False">
     
                        <telerik:RadTreeListView.ChildTableDefinitions>
                            <telerik:TreeListViewTableDefinition 
                                ItemsSource="{Binding Children}"/>
                        </telerik:RadTreeListView.ChildTableDefinitions>
                        <telerik:RadTreeListView.Columns>
     
                            <telerik:GridViewDataColumn
                                DataMemberBinding="{Binding Name, Mode=TwoWay}"
                                CellTemplate="{StaticResource TreeNodeTemplate}"
                                CellEditTemplate="{StaticResource TreeNodeEditTemplate}"
                                IsReadOnly="False"
                                Width="*"/>
     
                            <telerik:GridViewComboBoxColumn
                                x:Name="itemTypeColumn"
                                Header="Item Type"
                                DataMemberBinding="{Binding ItemTypeID, Mode=TwoWay}"
                                DisplayMemberPath="Name"
                                SelectedValueMemberPath="ID"
                                SortMemberPath="Order"
                                SortingState="Ascending"
                                ItemsSource="{Binding TypeModel.Items, Mode=TwoWay}"
                                IsReadOnly="True"
                                Width="150"/>
     
                            <telerik:GridViewDataColumn
                                DataMemberBinding="{Binding IsActive, Mode=TwoWay}"
                                Header="Include"/>
     
                        </telerik:RadTreeListView.Columns>
                    </telerik:RadTreeListView>

     

    The templates:

        <DataTemplate
            x:Key="TreeNodeTemplate">
            <StackPanel
                Orientation="Horizontal">
                <Image
                    Source="{Binding Image, Mode=TwoWay}"
                    ToolTip="{Binding Barcode, Mode=TwoWay}"/>
                <TextBlock
                    Text="{Binding Name, Mode=TwoWay}"
                    Margin="5"
                    ToolTip="{Binding Description}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate
            x:Key="TreeNodeEditTemplate">
     
            <StackPanel
                Orientation="Horizontal">
                <Image
                    Source="{Binding Image, Mode=TwoWay}"
                    VerticalAlignment="Top"/>
                <Grid
                    Margin="5"
                    Background="Cornsilk">
     
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="125"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
     
                    <Grid.RowDefinitions>
                        <RowDefinition Height="26"/>
                        <RowDefinition Height="26"/>
                        <RowDefinition Height="26"/>
                        <RowDefinition Height="26"/>
                    </Grid.RowDefinitions>
     
                    <Label
                        Content="ID:"
                        Grid.Column="0"
                        Grid.Row="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"/>
     
                    <TextBlock
                        Grid.Column="1"
                        Text="{Binding ID, Mode=TwoWay}"/>
     
                    <Label
                        Content="Name:"
                        Grid.Column="0"
                        Grid.Row="1"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"/>
     
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="1"
                        Text="{Binding Name, Mode=TwoWay}"
                        IsEnabled="{Binding IsEditableStatus}"/>
     
                    <Label
                        Content="Description:"
                        Grid.Column="0"
                        Grid.Row="2"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"/>
     
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="2"
                        Text="{Binding Description, Mode=TwoWay}"
                        IsEnabled="{Binding IsEditableStatus}"/>
     
                    <Label
                        Content="Barcode:"
                        Grid.Column="0"
                        Grid.Row="3"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"/>
     
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="3"
                        Text="{Binding Barcode, Mode=TwoWay}"/>
                </Grid>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>

  2. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 03 Jul 2015 Link to this post

    Hello Joel,

    Can you please share some details on how are you changing the enabled/disabled state of the TextBox? If you are not changing it at all, and have simply bound it to a boolean property which by default has "False" value, it will remain disabled.

    A way of updating the value of the boolean property would be to subscribe to the BeginningEdit event of RadGridView and set the given property of the item to "True".
    private void clubsGrid_BeginningEdit(object sender,
        GridViewBeginningEditRoutedEventArgs e)
    {
        var club = (e.Row).DataContext as Club;
     
        if (club != null)
        {
            club.IsEditableStatus = true;
        }
    }

    Can you please give it a try and let me know how it works for you?

    Regards,
    Stefan
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 06 Jul 2015 in reply to Stefan X1 Link to this post

    Actually, I thought I already answered your question by my original post.  The TextBox IsEditableStatus Boolean field is false and doesn't change throughout this exchange.  But, when I press a key in display state (where there is a TextBlock) the Name value still gets updated.  Its almost like when I load the edit state the TextBox control doesn't ask if the or isn't told that it shouldn't be enabled.
  5. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 07 Jul 2015 Link to this post

    Hello Joel,

    If you disregard RadTreeListView and define a simple TextBox bound to a boolean property, you will notice that the property will not be changed to "True" if you enter edit mode. This property needs to be set based on some logic.

    You can check the IsEnabled article as well the How to simultaneously enable/disable multiple controls blog post for further reference.

    Regards,
    Stefan
    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
Back to Top