Solved

Databinding Combobox

Posted on 2008-06-09
1
1,512 Views
Last Modified: 2013-11-26
Hi

 I have a combobox that I use databinding on.

Me.cboEmploymentCondition.DataBindings.Add(New System.Windows.Forms.Binding("Text", m_tbl_BindingSourceEmployed, "EmploymentCondition", True))

The problem is not if there are any data in the DB that matches the values in the combobox it's when it dosen't. If the data dosen't match any of the texts that's in the combobox it keeps the parent value.

So if I "send" "Test1" to the cbo it shows  "Test1" if this text is in the combobox.
If I then "send" "Test2" and that text dosen't exist in the cbo it will still show the text "Test1".
 If the text is missing I what the box to show a empty row (no text).

Is this possible to fix this?

I found this, but I can't get it to work
http://windowsclient.net/blogs/faqs/archive/2006/07/12/how-can-i-add-a-null-or-dbnull-entry-to-my-bound-combobox.aspx
/* Create a new Customer                          */
Customer cust = new Customer("Joe", null);
 
/* Add null value                                       */
DataRow row = statesTable.NewRow();
 
/* Enter a null row (ComboBox will show blank)          */
row["Name"] = "";
row["Code"] = DBNull.Value;
 
/* Add the row to DataTable                             */
statesTable.Rows.Add(row);
 
/* Bind the States ComboBox to the states DataTable     */
this.statesCB.DisplayMember = "Name";
this.statesCB.ValueMember = "Code";
this.statesCB.DataSource = statesTable;
 
/* Bind the ComboBox SelectedValue to the customer      */
/* business object                                      */
this.statesCB.DataBindings.Add("SelectedValue", cust, "StateID", true);

Open in new window

0
Comment
Question by:AWestEng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
AWestEng earned 0 total points
ID: 21784740
Ok then I will try to answer the question myself.

What I can understand from all the stuff I bben reading is the problem a related to a known "bug" in the combobox that is the main problem.

If I use a DevExpress combobox is works perfect.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question