string temp = "1998,1999,2000,2001";如何把上面的字符串绑定到comboBox上,选项一为1998,选项二为1999,选项三为2000,选项四为2001

解决方案 »

  1.   

    先split到一个数组中,然后以数组为数据源
      

  2.   

    try:string[] strs = temp.Split(",");
    foreach(string s in strs)
    {
      comboBox1.Items.Add(s);
    }
      

  3.   

    错误 1 与“string.Split(params char[])”最匹配的重载方法具有一些无效参数 D:\t\WindowsApplication2\WindowsApplication2\Form1.cs 23 29 WindowsApplication2错误 2 参数“1”: 无法从“string”转换为“char[]” D:\t\WindowsApplication2\WindowsApplication2\Form1.cs 23 40 WindowsApplication2
      

  4.   

    呵呵,其实这样就可以了string temp = "1998,1999,2000,2001";
    string[] arr = temp.Split(',');
    comboBox1.DataSource = arr;