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

GridViewDataColumn.DataMemberBinding with multiple sources

1 Answer 229 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 2
Christophe asked on 02 May 2011, 12:36 PM
Hello,

I need to create a GridView with a view model for each column (each column's view model is sharing with an another object).

This is my code behind:
...
for (int i = 0; i < max; i++)
{
    Binding MonBinding = new Binding("Points");
    MonBinding.Source = MonViewModel.CourbeTypeViewModels[i];
    MonBinding.Mode = BindingMode.OneWay;
 
    GridViewDataColumn GVDC = new GridViewDataColumn();
    GVDC.DataMemberBinding = MonBinding;
    GVDC.UniqueName = "ValCT" + i.ToString();
    GVDC.IsGroupable = false;
    GVDC.IsFilterable = false;
    GVDC.IsSortable = false;
    GVDC.IsReadOnly = true;
    Tableau.Columns.Add(GVDC);
}
...

My XAML :
...
<
telerik:RadGridView Name="Tableau" AutoGenerateColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False">
                <telerik:RadGridView.Columns/>
</telerik:RadGridView>
...

In child view model :
...
private ObservableCollection<decimal> _Points;
public ObservableCollection<decimal> Points
{
    get { return _Points; }
    set
    {
        _Points = value;
        OnPropertyChanged("Points");
    }
}
...

MonViewModel is my page view model (datacontext)
CourbeTypeViewModels is an ObservableCollection of CourbeTypeViewModel view model in MonViewModel
Points is an ObservableCollection<decimal> in each CourbeTypeViewModel
Tableau is a GridView in my page

This code creating 3 columns with header but without data...

My question : "How can I bind each column with it's own viewmodel ?"   

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 02 May 2011, 12:48 PM
Hi Christophe,

 

GridViewDataColumn is not designed to work in such scenarios. Why not use our ComboBoxColumn instead? 


Best wishes,
Vanya Pavlova
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
Christophe
Top achievements
Rank 2
Answers by
Vanya Pavlova
Telerik team
Share this question
or