Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to set all this value in combobox
string vlaue="12,13,15,16,14"

but how to remove common from it and how to set that value to combobox value.

What I have tried:

i have just try split() but not work.
Posted
Updated 2-Apr-18 6:45am
Comments
#realJSOP 2-Apr-18 12:35pm    
We don't link to that other site.
[no name] 2-Apr-18 12:38pm    
"We" mabye not, me will do it ;p

How can this "not work"?

C#
string[] parts = vlaue.Split(',');
 
Share this answer
 
Comments
[no name] 2-Apr-18 12:40pm    
Because it simply splits a string and does not yet added them to cb?
#realJSOP 2-Apr-18 12:41pm    
Well, he complained that using split didn't work. Beyond that, we don't know what platform he's using, so...

The quality of the answer is tied directly to the quality of the question.
Member 11776570 2-Apr-18 12:43pm    
it will work but at last there is empty value in combo box
Maciej Los 2-Apr-18 13:47pm    
5ed!
Try this:
C#
string vlaue="12,13,15,16,14";
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("vlaue"));
dt = vlaue.Split(new string[]{","}, StringSplitOptions.RemoveEmptyEntries)
	.Select(x => dt.LoadDataRow(new object[]{x}, false))
	.CopyToDataTable();
combobox1.DataSource = dt;
combobox1.ValueMember = "vlaue";
combobox1.DisplayMember = "vlaue";


More at:
How to: Bind a Windows Forms ComboBox or ListBox Control to Data | Microsoft Docs[^]
ComboBox Class (System.Windows.Forms)[^]
 
Share this answer
 
i have try this
string value = "12,15,16,14,18";
           string[] combovalue = value.Split(',');

           foreach (string itemvalue in combovalue)
           {
               cmb.Items.Add(itemvalue);
           }


done done... it is working
 
Share this answer
 
v2

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