Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding Linq to an xceed datagrid.
Message
From
26/02/2008 13:11:20
 
 
To
All
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Title:
Binding Linq to an xceed datagrid.
Miscellaneous
Thread ID:
01296509
Message ID:
01296509
Views:
125
I just can't seem to get this to work.

WPF:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using cdsLinq;

namespace cdsProWPF
  {
  /// <summary>
  /// Interaction logic for cdsBillsWPF.xaml
  /// </summary>
  public partial class cdsBillsWPF : UserControl
    {
    cdsLinqDataContext dc;
    IEnumerable<cdsPayablesRecord> Bills { get; set; }

    public cdsBillsWPF()
      {
      dc = new cdsLinqDataContext();
      Bills = dc.GetPayables();

      InitializeComponent();

      //If I include this line I get records.  If I don't it's all blank
      dataGridControl1.ItemsSource = Bills;
      }

    private void MenuItem_Click(object sender, RoutedEventArgs e)
      {
      System.Windows.Forms.MessageBox.Show(dataGridControl1.CurrentItem.ToString());
      }
    }
  }
LINQ:
namespace cdsLinq
  {

  partial class cdsLinqDataContext
    {

    public IEnumerable<cdsPayablesRecord> GetPayables()
      {
      cdsLinqDataContext dc = new cdsLinqDataContext();
      IEnumerable<cdsPayablesRecord> bills = from bill in dc.cdsBills
                                             join ent in dc.cdsEntities on bill.AccountXRef equals ent.ID
                                             select new cdsPayablesRecord(bill.DateDue, ent.Name, bill.Invoice, bill.Amount);
      return bills;
      }

    }

  public class cdsPayablesRecord
    {
    public DateTime DateDue { get; set; }
    public string   Name    { get; set; }
    public string   Invoice { get; set; }
    public decimal  Amount  { get; set; }

    public cdsPayablesRecord(DateTime dateDue, string name, string invoice, decimal amount)
      {
      DateDue = dateDue;
      Name    = name;
      Invoice = invoice;
      Amount  = amount;
      }
    }
  
  }
XAML:
<UserControl x:Class="cdsProWPF.cdsBillsWPF"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300" 
    xmlns:local="clr-namespace:cdsProWPF"             
    xmlns:xcdg="clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid">
  <Grid>
    <Grid.Resources>
      <xcdg:DataGridCollectionViewSource x:Key="dgcvs" Source="{Binding}">
        <xcdg:DataGridCollectionViewSource.ItemProperties>
          <xcdg:DataGridItemProperty Name="DateDue" ValuePath="cdsPayablesRecord.DateDue" />
          <xcdg:DataGridItemProperty Name="Name"    ValuePath="cdsPayablesRecord.Name" />
          <xcdg:DataGridItemProperty Name="Invoice" ValuePath="cdsPayablesRecord.Invoice"/>
          <xcdg:DataGridItemProperty Name="Amount" ValuePath="cdsPayablesRecord.Amount"/>
        </xcdg:DataGridCollectionViewSource.ItemProperties>
      </xcdg:DataGridCollectionViewSource>
      <!--<xcdg:DataGridCollectionViewSource x:Key="dgcvs"
                                         Source="{Binding Path=Bills}"/>-->
    </Grid.Resources>
    <xcdg:DataGridControl Name="dataGridControl1" ItemsSource="{Binding Source={StaticResource dgcvs}}" Margin="0,-3,0,3">
      <!--<xcdg:DataGridControl.Columns>
        <xcdg:Column DisplayMemberBinding="{Binding Path=DateDue}" FieldName="DateDue" Title="DateDue" />
        <xcdg:Column DisplayMemberBinding="{Binding Path=Name}" FieldName="Name" Title="Name" />
      </xcdg:DataGridControl.Columns>-->
      <xcdg:DataGridControl.ContextMenu>
        <ContextMenu>
          <MenuItem Header="test" Click="MenuItem_Click" />
        </ContextMenu>
      </xcdg:DataGridControl.ContextMenu>
    </xcdg:DataGridControl>
  </Grid>
</UserControl>
The XAML is a bit of a mess I've been trying it every way I can think of.

These are the main references I've been working with:

http://www.thedatafarm.com/blog/CommentView,guid,d7d04355-982a-42d8-92c5-d24e71f8cc7e.aspx#commentstart
http://forums.xceed.com/Forums/ShowPost.aspx?PostID=11292

Any Ideas?
Next
Reply
Map
View

Click here to load this message in the networking platform