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

Binding columns with data from orm list

3 Answers 212 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sam Ur
Top achievements
Rank 2
Sam Ur asked on 24 Aug 2010, 11:21 AM
Hi everyone, I'm newbie when it comes to WPF so i have some - maybe too basic question, but still. 
I have a question on how to populate specific columns in radgrid view with columns in List that i got from my orm model.

For example - this is my code behind to set datacontext of a grid view P.S. I would like to put that into resources:
public partial class MyClass : Page
    {
        public List<MyTable> myList { get; set; }
  
        public Drzava()
        {
            using (MyModel dbContext = new MyModel())
            {
                myList = dbContext.MyTable.ToList();
  
            }
            InitializeComponent();
              
            myGridView.DataContext = myList;
        }
    }

if I set ItemsSource="{Binding ElementName=myPage,Path=myList}" , i get populated all the columns, but i only want specific ones...so i tried somethink like that:
<telerik:RadGridView Name="myGridView" Margin="12,65,12,12" ItemsSource="{Binding ElementName=myPage,Path=myList}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn DataContext="{Binding Path=Id}"></telerik:GridViewColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
But I cannot get it to work...
Thank you in advance for the reply and help.

3 Answers, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 24 Aug 2010, 11:26 AM
Hi Sam Ur,

 You need the DataMemberBinding property of GridViewDataColumn, not DataContext.

Sincerely yours,
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
Sam Ur
Top achievements
Rank 2
answered on 24 Aug 2010, 11:43 AM
Hi Yavor, yeah that did it...damn it i was like busting my head for days because i was using gridviewcolumn instead of gridviewdatacolumn.
This...

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Id}"  />
Did the trick...thanks.
Oh can i ask another question...how can i set orm objects in XAML, maybe with the use of collectionview and collectionview source or something like that.

Thank you again!
0
Accepted
Yavor Georgiev
Telerik team
answered on 27 Aug 2010, 10:25 AM
Hi Sam Ur,

 Please check out this forum thread. It shows how to bind a RadGridView to the View of a CollectionViewSource. Even though the project is for Silverlight, you can use the exact same approach in WPF.

Kind regards,
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
Tags
GridView
Asked by
Sam Ur
Top achievements
Rank 2
Answers by
Yavor Georgiev
Telerik team
Sam Ur
Top achievements
Rank 2
Share this question
or