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

RadGridView Cell Different Behaviour

3 Answers 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 19 Apr 2011, 06:57 AM
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.


3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 19 Apr 2011, 03:20 PM
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
0
Ravi
Top achievements
Rank 1
answered on 19 Apr 2011, 05:17 PM

 

 

 

 

<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




0
Accepted
Maya
Telerik team
answered on 20 Apr 2011, 07:52 AM
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
Tags
GridView
Asked by
Ravi
Top achievements
Rank 1
Answers by
Maya
Telerik team
Ravi
Top achievements
Rank 1
Share this question
or