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

Columns that are editable only when adding?

2 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 30 Dec 2011, 09:47 PM
I have a pretty simple use case: I have a grid populated from a database, with a column for each field.

I want the user to be able to add new records, and to edit existing records.

My problem is the fields that are part of the primary key.  I need these to be editable, when the user is adding a new record, but to not be editable, when the user is editing an existing record.

Seems like a pretty common problem, but I've not been able to figure out how to do it.

If it matters, I'm using MVVM and my records are in an ObservableCollection.  My ViewModel picks up on changes to the collection with a NotifyCollectionChangedEventHandler on the collection, and changes to individual records with a PropertyChangedEventHandler on each record.  I don't actually have any GUI events being handled in the codebehind.

2 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 02 Jan 2012, 12:30 PM
Hello,

You can create a bool property in your ViewModel which says whether you can edit the desired field or not. Than you can set the IsReadOnlyBinding on the column that you desire to suit your needs.

<telerik:GridViewDataColumn DataMemberBinding="{Binding Id, Mode=TwoWay}" Header="Id" IsReadOnlyBinding="{Binding IsFinal}"/>

I am attaching a simple project for further reference. 

Hope this helps!

All the best,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jeff
Top achievements
Rank 1
answered on 03 Jan 2012, 04:58 PM
That seems like a very clean solution.  Thanks.
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or