Split String and add in combobox in c# -


im getting data database , adding combobox.the string contains list of names comma.

datarow dr = newdt.rows[i]; traineecombo.items.add(dr["trainee"].tostring()); 

it works fine want split string , add each item combobox. tried below methods.

 datarow dr = newdt.rows[i];  string temptr = dr["trainee"].tostring();  string[] result = temptr.split(new char[] {','});  foreach (string s in result)       {         if (s.trim() != "")         traineecombo.items.add(s);        } 

second method:

string temptr = dr["trainee"].tostring(); traineecombo.items.addrange(temptr.split(',')); 

but both methods shows error

cannot convert string char[] , invalid arguments. got piece of sample code msdn.how can solve it?

try this

datarow dr = newdt.rows[i]; string temptr = dr["trainee"].tostring(); string[] result = temptr.split(','); foreach (string s in result)   {     if (s.trim() != "")     traineecombo.items.add(s);    } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -