Solved

Databinding Combobox

Posted on 2008-06-09
1
1,507 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now