binding a datatable to a WPF combo is not working.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • moondaddy

    binding a datatable to a WPF combo is not working.

    Using c# 3.5, I'm trying to bind a data table to a combo box, but I cant see
    any data in the list. I'm sure the data table has data. Here's my code:

    DataSet ds = GetData();
    DataTable tb = ds.Tables["tb"];
    myCombo.DataCon text = tb;
    myCombo.Display MemberPath = tb.Columns["Name"].ToString();
    myCombo.Selecte dValuePath = tb.Columns["ID"].ToString();

    any idea what I'm doing wrong?

    --
    moondaddy@newsg roup.nospam


  • Walter Wang [MSFT]

    #2
    RE: binding a datatable to a WPF combo is not working.

    You will need to use the ItemsSource property and we also need to
    explicitly convert the DataTable into a list:

    DataTable dt = new DataTable();
    dt.Columns.Add( "Code");
    dt.Columns.Add( "Name");
    dt.Rows.Add("c1 ", "n1");
    dt.Rows.Add("c2 ", "n2");
    myCombo.ItemsSo urce = ((IListSource)d t).GetList();
    myCombo.Display MemberPath = "Code";
    myCombo.Selecte dValuePath = "Name";


    Reference:

    Beatriz Costa Binding to ADO.NET (http://www.beacosta.com/blog/?cat=12)


    Regards,
    Walter Wang (wawang@online. microsoft.com, remove 'online.')
    Microsoft Online Community Support

    =============== =============== =============== =====
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    =============== =============== =============== =====

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • moondaddy

      #3
      Re: binding a datatable to a WPF combo is not working.

      Thanks.

      ""Walter Wang [MSFT]"" <wawang@online. microsoft.comwr ote in message
      news:0pz1aPGbIH A.360@TK2MSFTNG HUB02.phx.gbl.. .
      You will need to use the ItemsSource property and we also need to
      explicitly convert the DataTable into a list:
      >
      DataTable dt = new DataTable();
      dt.Columns.Add( "Code");
      dt.Columns.Add( "Name");
      dt.Rows.Add("c1 ", "n1");
      dt.Rows.Add("c2 ", "n2");
      myCombo.ItemsSo urce = ((IListSource)d t).GetList();
      myCombo.Display MemberPath = "Code";
      myCombo.Selecte dValuePath = "Name";
      >
      >
      Reference:
      >
      Beatriz Costa Binding to ADO.NET (http://www.beacosta.com/blog/?cat=12)
      >
      >
      Regards,
      Walter Wang (wawang@online. microsoft.com, remove 'online.')
      Microsoft Online Community Support
      >
      =============== =============== =============== =====
      When responding to posts, please "Reply to Group" via your newsreader so
      that others may learn and benefit from your issue.
      =============== =============== =============== =====
      >
      This posting is provided "AS IS" with no warranties, and confers no
      rights.
      >

      Comment

      Working...