Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had to find out how to set values into ComboBox items

So i have a combo box with two string items and each item make some changes on other combo box then savee to xml

Now i tried to set value for this items but the problem is the xml output shows only 1 value

What I have tried:

comReg.DisplayMember = "Item 1";
     comReg.ValueMember = "1";

     comReg.DisplayMember = "Item 2";
     comReg.ValueMember = "2";


     comPer.Items.Clear();
     switch (comReg.SelectedItem.ToString()) {
     case "Item 1":
             comPer.Items.AddRange(new string[]{"1", "2", "3", "4" });
     break;
     case "Item 2":
             comPer.Items.AddRange(new string[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"});
     break;
Posted
Updated 17-May-20 20:16pm
Comments
BillWoodruff 18-May-20 0:28am    
hi, to assist you, we need to see the xml, and the code that is generating the xml.
BillWoodruff 20-May-20 1:42am    
is your question solved now ?

1 solution

You're using DisplayMember[^] and ValueMember[^] properties wrong way.

In both cases the description is:
MSDN wrote:
A String specifying the name of an object property that is contained in the collection specified by the DataSource property. The default is an empty string ("").


So, to be able to use them, you need to set ListControl.DataSource Property (System.Windows.Forms) | Microsoft Docs[^]

Follow the links to get more details.
 
Share this answer
 
Comments
BillWoodruff 19-May-20 2:10am    
+5
Maciej Los 19-May-20 2:12am    
Thank you, Bill.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900