RadGridView Cell Different Behaviour

4 posts, 1 answers
  1. Ravi
    Ravi avatar
    104 posts
    Member since:
    Oct 2012

    Posted 19 Apr 2011 Link to this post

    Hi I have implemented a hierarchical grid, i have 4 columns in the child grid in which 3 columns are editable, that means the CellEditTemplate is set for the first 3 columns which becomes a Textbox while in edit or add mode.

    What i need is, In edit mode the first cell should remain non-editable and new row it should be editable.

    screen shot attached for more clarity.

    Also please do let me know how to set the CellEditTemplate programatically.

    Please advice.


  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Apr 2011 Link to this post

    Hello David,

    Considering your first requirement, you may take a look at this forum thread for a reference.
     As for the second one, you may define a DataTemplate and set it in the code-behind as follows:

    XAML:
    <UserControl.Resources>        
            <DataTemplate x:Key="MyDataTemplate">
                <TextBox Background="Tomato" Foreground="Yellow" Text="{Binding Name}" />
            </DataTemplate>
    </UserControl.Resources>
     
    C#:
    public MainPage()
            {
                InitializeComponent();
     
                this.clubsGrid.Columns[1].CellEditTemplate = (DataTemplate)this.Resources["MyDataTemplate"];
            }

    In case you want to define everything in the code-behind, you may take a look at this article for further information. 
     

    Regards,
    Maya
    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
  3. Ravi
    Ravi avatar
    104 posts
    Member since:
    Oct 2012

    Posted 19 Apr 2011 Link to this post

     

     

     

     

    <telerikGridView:GridViewDataColumn Width="250" x:Name="colItem_Number" DataMemberBinding="{Binding Item_Number}">
                                    <telerikGridView:GridViewDataColumn.Header>
                                        <TextBlock Text="Item Number"/>
                                    </telerikGridView:GridViewDataColumn.Header>
                                    <telerikGridView:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Item_Number, Mode=TwoWay}" Tag="{Binding}"/>
                                        </DataTemplate>
                                    </telerikGridView:GridViewDataColumn.CellTemplate>                                
                                </telerikGridView:GridViewDataColumn>
    <DataTemplate x:Key="edittableTextbox">
                <input:AutoCompleteBox x:Name="acb" Text="{Binding Item_Number, Mode=TwoWay}" Loaded="acb_Loaded"></input:AutoCompleteBox>
            </DataTemplate>

    Please find XAML code above, when the grid is populated with data, and if i double click or press F2, the grid gets into EDIT mode which is expected, but the first column still becomes editable which i dont want.

    I Want the first column to be editable only if the user clicks on "Add new Item" otherwise the first columns always should be non-editable

    please provide your valuable comments

    Thanks
    Shiras




  4. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 Apr 2011 Link to this post

    Hi David,

    You may handle the BeginningEdit and RowEditEnded events. The idea would be to set the column's IsReadOnly property to "False" in the first event and set it back in the second one. 
    It may be something similar to:

    private void clubsGrid_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
            {
                if (this.clubsGrid.Items.CurrentAddItem == e.Row.Item)
                {
                    this.clubsGrid.Columns[0].IsReadOnly = false;
                
            }
            private void clubsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
            {
                this.clubsGrid.Columns[0].IsReadOnly = true;
            }

    You may get the required column by using its UniqueName as well.
    Please let me know whether it corresponds to your requirements.
     

    Best wishes,
    Maya
    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
Back to Top