Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / June 2004

Tip: Looking for answers? Try searching our database.

Data in Combobox after Databinding

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank Lamers - 29 Jun 2004 16:58 GMT
Hi,

I have a problem with a Combobox after binding to a datatable. I displayed  a column of a table with code similiar to what Tom Krueger mentioned here:

System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter(
   "Select * from Customers", conn);
da.Fill(ds);

System.Data.DataTable dt = ds.Tables[0];
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "CustomerID";

This works fine, the column 'CustomerID' is displayed. Now the problem:  

1. I can just assign values which are already listed in the column.
 Example:
 comboBox1.Text = "4711"
 assigns the text '4711' only if it is listed in the column 'CustomerID' (and by this in the list of the combobox). Otherwise the text is unchanged.
2. I cannot check the Combobox whether it contains the string
 Example:
 if not comboBox1.Items.Contains("4711") then...
 will always result in the string being NOT in the combobox regardless whether it is part in the datatable colum (and by this in the combobox) or not.

Any ideas how to solve this problem?

Regards

Frank Lamers
William Ryan  eMVP - 29 Jun 2004 23:56 GMT
If you add a datarow to the underlying table with the value you want, it
will appear in the combobox.  You can use the DataTable.Select method to
query for a given value

Signature

W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups

Hi,

I have a problem with a Combobox after binding to a datatable. I displayed
a column of a table with code similiar to what Tom Krueger mentioned here:

System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter(
   "Select * from Customers", conn);
da.Fill(ds);

System.Data.DataTable dt = ds.Tables[0];
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "CustomerID";

This works fine, the column 'CustomerID' is displayed. Now the problem:

1. I can just assign values which are already listed in the column.
 Example:
 comboBox1.Text = "4711"
 assigns the text '4711' only if it is listed in the column 'CustomerID'
(and by this in the list of the combobox). Otherwise the text is unchanged.
2. I cannot check the Combobox whether it contains the string
 Example:
 if not comboBox1.Items.Contains("4711") then...
 will always result in the string being NOT in the combobox regardless
whether it is part in the datatable colum (and by this in the combobox) or
not.

Any ideas how to solve this problem?

Regards

Frank Lamers

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.