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

Two-Way Databinding with RadGridView

4 Answers 506 Views
GridView
This is a migrated thread and some comments may be shown as answers.
TSRG - IT
Top achievements
Rank 1
TSRG - IT asked on 25 May 2010, 08:51 AM
Hi guys,

I'm using the MVVM pattern and I've got my RadGridView bound to a BindingList of business objects, within the business objects there are various strings and a binding list of decimals. Below is a stripped down version of the set up I have:

public class ARow
{
string column1;
string column2;
BindingList<decimal> values;
}

BindingList<ARow> allRows;

XAML:
<telerik:RadGridView ItemsSource = "{Binding allRows, Mode=TwoWay}">

The columns are manually added and have two way binding set up in the code behind.

I would like to implement two way data binding whereby changes to values in the BindingList<decimal> values will be reflected in the grid itself. I am able to successfully change the underlying data source however this is not reflected in the grid itself.

I have also tried, instead of using "decimal" using a custom class "ValueObject" I created which contains a decimal property as follows, but to no avail. The code is as follows:

public class ValueObject : INotifyPropertyChanged
{
    _private decimal _value;
    public decimal Value
    { 
        get { return _value; } set { _value = value; OnPropertyChanged("Value"); }
    }
}

Any help would be great!

Cheers,

Tim.

4 Answers, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 25 May 2010, 10:23 AM
Hi Timothy Lin,

 Is there a particular reason why you want to use BindingList, instead of ObservableCollection or our own ObservableItemCollection? Also, you employ a master-detail view, correct? I need to know a bit more about your scenario before I can be of further assistance.

Greetings,
Yavor Georgiev
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
TSRG - IT
Top achievements
Rank 1
answered on 28 May 2010, 08:56 AM
Hi Yavor Georgiev,

Thank you for your reply, I realised that I had to call the PropertyChanged event handler within the List Changed event handler of the BindingList. The reason I was using a BindingList was because I wanted to capture the events when an item changes, which, the ObservableCollection did not provide! But it's fixed for now!

Cheers,

Tim.
0
Kiran
Top achievements
Rank 1
answered on 03 Sep 2010, 08:58 AM
Hi

I have similar problem I am not able to make the Two-Way binding work.

I have a class

public class TransformedPermission : INotifyPropertyChanged
{
    public long TaskID
    {
        get;
        set;
    }
    public long ParentTaskID
    {
        get;
        set;
    }
    public System.Guid RoleId
    {
        get;
        set;
    }
    public string TaskName
    {
        get;
        set;
    }
    public string TaskTypeDescription
    {
        get;
        set;
    }
    ObservableCollection<bool> permissionValues = new ObservableCollection<bool>();
    public ObservableCollection<bool> PermissionValues
    {
        get { return this.permissionValues; }
    }
    public event PropertyChangedEventHandler PropertyChanged;
}

Then I create an observable collection of this class

private ObservableCollection<TransformedPermission> _transformedPermissionList = new ObservableCollection<TransformedPermission>();
  
 public ObservableCollection<TransformedPermission> RolePermissionsList
        {
            get { return _transformedPermissionList; }
            set
            {
                _transformedPermissionList = value;
                RaisePropertyChanged("RolePermissionsList");
            }
        }

I use code behind to set the Item Source:

tngGVFrameworkPermissions.ItemsSource = RolePermissionsList;

I want to bind the data using TwoWay binding in XAML
<telerik:RadGridView Name="tngGVFrameworkPermissions" AutoGenerateColumns="False" ItemsSource="{Binding Path=RolePermissionsList, Mode=TwoWay}"/>

If I comment out the code in code behind nothing gets bind.

I am looking for a working solution using MVC pattern can you share a working solution with similar requirement



0
Vlad
Telerik team
answered on 03 Sep 2010, 09:04 AM
Hi,

 You have auto-properties for your object and PropertyChanged is never raised.

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
Tags
GridView
Asked by
TSRG - IT
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
TSRG - IT
Top achievements
Rank 1
Kiran
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or