You must Sign In to post a response.
  • Category: .NET

    Splitting Strings and Add into combo box in vb.net

    Dear All,

    i have a string 'April,May,June'.
    I need to split this string by separated and added into Combo Box using vb.net

    when i select anyone value in Name of Quarter Combobox, the Name of Month Combobox have to load this by adding separately 1. April
    2. May
    3. June.

    is it possible ?


    Regards,
    Ramkumar G.R
  • #749164
    You can write the code as below





    string strMonth = "April,May,June";

    string[] strMonthArray = strMonth.Split(',');

    for(int i=0; I< strMonthArray.Length;i++ )
    {
    cmbBox1.Items.Add(strMonthArray[I].ToString();
    }


    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #749165
    You can split string by "," and than use for loop to insert value in combobox.
    I have created snippet for you take a look.

    Dim Data As String = "April,May,June'"

    Dim i As Integer
    For i = 0 To Data.Split(",").Count()- 1 Step i + 1
    Dim MonthName As String = Data.Split(",")(i).ToString()

    checkedListBox1.Items.Add(i + 1,MonthName))
    'ComboboxID.items.Add("value","text");
    Next

    check aboove code i have convert it from c# code which i have created so may be some syntax error in it, update it and use it.

    C# code

    string Data = "April,May,June'";
    for (int i = 0; i < Data.Split(',').Count(); i++)
    {
    string MonthName = Data.Split(',')[i].ToString();

    checkedListBox1.Items.Add(i + 1,MonthName));
    //ComboboxID.items.Add("value","text");

    }

    Regards,
    Nirav Prabtani (Senior Web Developer)
    Email : niravjprabtani@gmail.com
    blog : niravprabtani.blogspot.in

  • #749170
    Hello
    You Can use following Code

    Dim s As String = "Jan,fab,March"
    Dim lst As New List(Of String)
    lst = s.Split(",").ToList()
    ComboBox1.DataSource = lst

    Thanks
    Umesh Bhosale

  • #749181
    Hi,

    Try something like below

    string result="jan,feb,march";
    String[] param = result.Split(',');
    foreach(string str in param)
    {
    cmb1.Items.Add(str);
    }


    Try something like above to achieve your goal....

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments