Solved

Databinding Combobox

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

728 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