ComboxBox with Display & Value pair (Datasource) in C#

  • Thread starter Thread starter vijai thoppae
  • Start date Start date
V

vijai thoppae

Hello..

I'm having a strange problem with the comboxbox with DataSource & using
DisplayMember,ValueMember properties. The problem is if i supply a item
which is not in the DataSource array List i'm explicitly calling
SelectedIndex = -1 twice(as per Documentation in MS web site) to show empty
selection. When i visit the form for the 1st time it selects the 0th index
by default ,on subsequent visits it displays correctly. Rightnow with a
workaround i'm refreshing the sameform twice to make it work. Is there a
real reason for this problem. I guess its a bug when we use DataBinding. In
the case of normal ComboxBox using AddRange it displays correctly.

Any comments pls.?

Thanks,
Vijai
 
Hi Vijai,

I tried to reproduce this problem on my system using the following code
snippet and it seems working correctly:
<code>
//form2 was created and showed by a button click on form1
//the test database is Categories table in FPWind.mdb
//ValueMember = "Categories.CategoryID"
//DisplayMember = "Categories.CategoryName"
private void Form2_Load(object sender, System.EventArgs e)
{
oleDbDataAdapter1.Fill (dataSet11);
comboBox1.SelectedValue = 1121;
comboBox1.SelectedIndex = -1;
comboBox1.SelectedIndex = -1;
}
</code>
To assist you investigating this problem further, I need more information
about how to reproduce this problem. Could you give the detail steps to
reproduce this problem.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Hello,
My scenario is quite different from yours. I've a parent App which contains
a Listview on leftside & panel on rightside.In the constructor i create a
bunch of user controls & assign click event to each item in the Listview.
One of the usercontrol contains a Comboxbox to which i assign a Datasource
from an ArrayList using Displaymember & Valuemember. Whenever user clicks
the ListViewItem say Test1, it displays the corresponding usercontrol on the
rightside. When i visit for the 1st time & if the item which i supply
doesn't match the ComboBox List then i explicitly set the SelectedIndex = -1
twice. Looks like i need to visit this page atleast once before i can see a
empty selection in the comboxbox.

hope this helps you to reproduce it.

Thanks,
vijai
 
Hi vijai,
Thanks for your reply!
From your description, my understanding to your problem now is
You have a form which contains a Listview on the left , there are several
list items in the listview and each of them has been assigned with a user
control. when user click on one listitem, you put corresponding user
control into the right panel.

So the comboBox is on the user control not a new form,right?
I'm trying to build a test program base on your description, but I'm not
clear how should I write it in detail level.
such as, when did you create and set databinding to your user control? Is
it created in the click event handler of the listview item or it's already
bounded in form initialization and just made visible in the event handler?
Also I'm not sure in which event handler did you set the SelectedIndex = -1
twice?

Due to this problem maybe hard to describe clearly, I think it would be
helpful if you can send me a simple sample project to help reproduce the
problem, then I can take a look into the code and see if can figure out
the answer.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top