怎样读取txt内容到combobox数组?

speedfisherman 2010-08-17 10:23:47
如题,
比如定义了一个ComboBox[] fillComboboxArray = new ComboBox[] { comboBox1, comboBox2, comboBox3, comboBox4, comboBox5, comboBox6, comboBox7, comboBox8, comboBox9 };

String content = sr.ReadToEnd();

String[] ss = content.Split(new char[] { '\n', '\r', '~' }, StringSplitOptions.RemoveEmptyEntries);

for (int i = 0; i < ss.Length; i++)
{

fillComboBoxArray[i].Text = ss[i];
}

但是这里的fillComboBoxArray[i].Text是被报错的,因为没有这个函数。
求高手赐合适的方法啊!!拜谢了
...全文
144 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
speedfisherman 2010-08-17
  • 打赏
  • 举报
回复
太崩溃了,原来是我把fillComboboxArray写成了fillComboBoxArray
一个b被大写了。。。。。。。。。。。浪费我两个小时。。。。。。。
这就给各位送分
兔子-顾问 2010-08-17
  • 打赏
  • 举报
回复
static void Main(string[] args)
{
ComboBox comboBox1 = new ComboBox();
ComboBox comboBox2 = new ComboBox();
ComboBox comboBox3 = new ComboBox();
ComboBox comboBox4 = new ComboBox();
ComboBox comboBox5 = new ComboBox();
ComboBox comboBox6 = new ComboBox();
ComboBox comboBox7 = new ComboBox();
ComboBox comboBox8 = new ComboBox();
ComboBox comboBox9 = new ComboBox();
ComboBox[] fillComboboxArray = new ComboBox[] { comboBox1, comboBox2, comboBox3, comboBox4, comboBox5, comboBox6, comboBox7, comboBox8, comboBox9 };

String content = "";

String[] ss = content.Split(new char[] { '\n', '\r', '~' }, StringSplitOptions.RemoveEmptyEntries);

for (int i = 0; i < ss.Length; i++)
{

fillComboboxArray[i].Text = ss[i];
}

Console.ReadKey();
}


没报错啊。
speedfisherman 2010-08-17
  • 打赏
  • 举报
回复
不对啊,这里不管是
fillComboBoxArray[i].Items.Insert(0, new ListItem("", ""));
还是
fillComboBoxArray[i].Items.Add("a");
编译都会报错说
The name 'fillComboBoxArray' does not exist in the current context
难道是忘了using 某个类库了吗?

我已经有的是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
lmdkboy 2010-08-17
  • 打赏
  • 举报
回复
楼上的都是正解~~~
阿双2009 2010-08-17
  • 打赏
  • 举报
回复
fillComboBoxArray[i].Items.Add(ss[i]);
wuyq11 2010-08-17
  • 打赏
  • 举报
回复
fillComboBoxArray[i].Items.Insert(0, new ListItem("", ""));
fillComboBoxArray[i].Items.Add("a");

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧