PC Review


Reply
Thread Tools Rate Thread

binding a datatable to a WPF combo is not working.

 
 
moondaddy
Guest
Posts: n/a
 
      8th Feb 2008
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.DataContext = tb;
myCombo.DisplayMemberPath = tb.Columns["Name"].ToString();
myCombo.SelectedValuePath = tb.Columns["ID"].ToString();

any idea what I'm doing wrong?

--
(E-Mail Removed)am


 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      11th Feb 2008
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.ItemsSource = ((IListSource)dt).GetList();
myCombo.DisplayMemberPath = "Code";
myCombo.SelectedValuePath = "Name";


Reference:

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


Regards,
Walter Wang ((E-Mail Removed), 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.

 
Reply With Quote
 
moondaddy
Guest
Posts: n/a
 
      12th Feb 2008
Thanks.

""Walter Wang [MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.ItemsSource = ((IListSource)dt).GetList();
> myCombo.DisplayMemberPath = "Code";
> myCombo.SelectedValuePath = "Name";
>
>
> Reference:
>
> Beatriz Costa Binding to ADO.NET (http://www.beacosta.com/blog/?cat=12)
>
>
> Regards,
> Walter Wang ((E-Mail Removed), 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView, dataTable and two way binding witek Microsoft ASP .NET 0 18th Jul 2006 03:41 PM
Binding combo box to datatable =?Utf-8?B?Qm9iMTczOQ==?= Microsoft Dot NET 1 4th Oct 2004 04:10 PM
partial datatable binding Dunc Microsoft C# .NET 0 27th Sep 2003 03:31 PM
Re: ListBox DataTable Binding.. Tony Microsoft Dot NET Framework Forms 0 22nd Jul 2003 08:38 AM
Binding a ComboBox to a DataTable Tony Microsoft Dot NET Framework Forms 0 22nd Jul 2003 08:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 AM.