comboBox获取文本档每行的数据 comboBox如何获取(新建文本文档)每行的数据? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 streamreader去readline,然后将readline的内容添加到combox的items 按行读文本放到comboBox里System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default); string strLine = sr.ReadLine(); while (strLine != null) { comboBox.Items.Add(strLine); strLine = sr.ReadLine(); } sr.Close(); 您好,刚才测试了下是可以的,请问下 获取后让comboBox直接选中刚才文本档里首个值如何实现? System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default); string strLine = sr.ReadLine(); while (strLine != null) { comboBox.Items.Add(strLine); strLine = sr.ReadLine(); } sr.Close(); if(comboBox.Items.Count>0) //默认选中第一个 comboBox.SelectedIndex=0; File.ReadAllLines("D:\\1.txt", Encoding.Default).ToList().ForEach(t => comboBox1.Items.Add(t)); if (comboBox1.Items.Count > 0) comboBox1.SelectedIndex = 0; 刚才我发现了个小问题,就是我连续点击button的时候 获取了两次数据 是不是点击button的时候 做个判断?点击button的时候先判断comboBox里是否有值如果没有值 那就填充进去,如果有值就循环遍历比对下 有的就不添加,没有的就添加这样的思路有问题吗? 点击button的时候,先清空下拉框内容 comboBox1.Items.Clear(); System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default); string strLine = sr.ReadLine(); while (strLine != null) { comboBox.Items.Add(strLine); strLine = sr.ReadLine(); } sr.Close(); if(comboBox.Items.Count>0) //默认选中第一个 comboBox.SelectedIndex=0; comboBox.Items.Clear(); //先清除,再加就没事了System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default); string strLine = sr.ReadLine(); while (strLine != null) { comboBox.Items.Add(strLine); strLine = sr.ReadLine(); } sr.Close(); if(comboBox.Items.Count>0) //默认选中第一个 comboBox.SelectedIndex=0; 【求助】C#如何使用DOS命令 模拟软键盘 点击软键盘TextBox中的光标总在最前面 treeview 指定层次查找 一个奇怪的问题 求助,跪求高手帮助. 修改时间中的小时数 关于1.1 版本写xml文件,请大家指点 C#中RSA的数据加密问题 C#中处理图片的问题很急. 求用Membership类和GridView控件实现用户编辑的代码 没有美工的情况下,有什么可以美化。net界面的方法吗?请大家多多指教 12306自动登录软件模拟
string strLine = sr.ReadLine();
while (strLine != null)
{
comboBox.Items.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default);
string strLine = sr.ReadLine();
while (strLine != null)
{
comboBox.Items.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
if(comboBox.Items.Count>0) //默认选中第一个
comboBox.SelectedIndex=0;
if (comboBox1.Items.Count > 0)
comboBox1.SelectedIndex = 0;
是不是点击button的时候 做个判断?
点击button的时候先判断comboBox里是否有值
如果没有值 那就填充进去,如果有值就循环遍历比对下 有的就不添加,没有的就添加
这样的思路有问题吗?
System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default);
string strLine = sr.ReadLine();
while (strLine != null)
{
comboBox.Items.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
if(comboBox.Items.Count>0) //默认选中第一个
comboBox.SelectedIndex=0;
System.IO.StreamReader sr = new System.IO.StreamReader("c:\\A.txt", System.Text.Encoding.Default);
string strLine = sr.ReadLine();
while (strLine != null)
{
comboBox.Items.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
if(comboBox.Items.Count>0) //默认选中第一个
comboBox.SelectedIndex=0;