in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Binding to DataTable

Last post 07-22-2008 8:02 PM by AlfonsoRojas. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 04-15-2008 9:18 AM

    Binding to DataTable

    Hi ,

    Could you please give me a quick sample of how to bind to a datatable in code-behind? Can't seem

    to find any help on that.

     

     

  • 05-08-2008 12:09 PM In reply to

    Re: Binding to DataTable

    Did you ever make any progress on this? I haven't found any examples either.

    Seems as if we are the only people in the world trying to actually use this stuff. I'm about ready to look elsewhere...

  • 05-08-2008 2:44 PM In reply to

    Re: Binding to DataTable

    No never got it working, we have already gone with another component.
  • 05-08-2008 7:52 PM In reply to

    Re: Binding to DataTable

    Thanks. So far I've been extreamly disappointed in the WPF components. They look beautiful, and I wish I could use them. But, the total lack of help and real world samples, or forums, or support, is just making it not worth it. I submitted a "Support Incident" asking for help on this today, we'll see..... they are losing a customer a little bit (well actually a lot of bit) everyday I waste on this.

    Would you mind saying who's component you went with? 

  • 05-13-2008 5:06 AM In reply to

    Re: Binding to DataTable

    Here is the sample code(C# + XAML) that builds chart using data table from NorthWind database.

    C# (Creating dataset)
    ...
    DataSet _dataSet;

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      // create connection and fill data set
      string mdbFile = @"c:\db\nwind.mdb";
      string connString = string.Format(
        "Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}",
        mdbFile);
      OleDbConnection conn = new OleDbConnection(connString);
      OleDbDataAdapter adapter = new OleDbDataAdapter(
         @"SELECT TOP 10 ProductName, UnitPrice FROM Products
           ORDER BY UnitPrice;", conn);

      _dataSet = new DataSet();
      adapter.Fill(_dataSet, "Products");

      // set data table rows as the source for chart data
      c1Chart1.Data.ItemsSource = _dataSet.Tables["Products"].Rows;
    }
    ...


    XAML ( data binding settings)

    ...
    <my:C1Chart.Data>
      <my:ChartData ItemNameBinding="{Binding Path=[ProductName]}">
        <my:DataSeries ValueBinding="{Binding Path=[UnitPrice]}"/>
      </my:ChartData>
    </my:C1Chart.Data>
    ...

  • 05-13-2008 8:56 AM In reply to

    • C1_JohnF
    • Top 25 Contributor
    • Joined on 08-02-2006
    • Pittsburgh, PA USA
    • Posts 226

    Re: Binding to DataTable

    Hi all,

    I am attaching a quick tutorial that our Documentation team put together for Data Binding in WPFChart. (See post further down for updated tutorial)

    Thanks!

    John Franco
    johnf@componentone.com
    Customer Engagement Manager
    www.componentone.com
  • 05-13-2008 4:33 PM In reply to

    Re: Binding to DataTable

    Thanks very much. This did the trick. 

  • 05-13-2008 4:36 PM In reply to

    Re: Binding to DataTable

    Thanks Alex, this is all I needed. Had it working in a few minutes! 

  • 05-28-2008 12:25 PM In reply to

    • C1_JohnF
    • Top 25 Contributor
    • Joined on 08-02-2006
    • Pittsburgh, PA USA
    • Posts 226

    Re: Binding to DataTable

     Hi all,

    I am attaching an updated tutorial. Just some minor changes to the intro paragraphs.

    Thanks!

    John Franco
    johnf@componentone.com
    Customer Engagement Manager
    www.componentone.com
  • 07-22-2008 8:02 PM In reply to

    Re: Binding to DataTable

    Private _ChartData1 As New ChartData

    Private Sub Window1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated

    Me.C1Chart1.Data = _ChartData1

    End Sub

    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

    ' create connection and fill data set

    Dim mdbFile As String = "c:\Program Files\ComponentOne Studio.NET 2.0\Common\nwind.mdb"

    Dim connString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile)

    Dim conn As New OleDbConnection(connString)

    Dim adapter As New OleDbDataAdapter("SELECT TOP 10 ProductName, UnitPrice" & Chr(13) & "" & Chr(10) & " FROM Products ORDER BY UnitPrice DESC;", conn)

    Dim DataSet As New DataSet

    Dim Series1 As New DataSeries

    adapter.Fill(DataSet, "Products")

    ' set source for chart data

    With _ChartData1

    .ItemsSource = DataSet.Tables("Products").Rows

    .ItemNameBinding = New Binding("[ProductName]")

    .Children.Add(Series1)

    Series1.ValueBinding =
    New Binding("[UnitPrice]")

    End With

    End Sub

Page 1 of 1 (10 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.