for (int i = 0; i < listBox1.Items.Count; i++)
{
//循环获取选中字段的英文名
string str=(this.listBox1.Items[i] as MyItemlist).Value;
//循环获取选中字段的中文名
string titleName = (this.listBox1.Items[i] as MyItemlist).Text;
cName += titleName + ",";
eName += str+",";
}
string str=(this.listBox1.Items[i] as MyItemlist).Value;
这句话报错,没有被实例化是什么原因啊?,谢谢了。
{
//循环获取选中字段的英文名
string str=(this.listBox1.Items[i] as MyItemlist).Value;
//循环获取选中字段的中文名
string titleName = (this.listBox1.Items[i] as MyItemlist).Text;
cName += titleName + ",";
eName += str+",";
}
string str=(this.listBox1.Items[i] as MyItemlist).Value;
这句话报错,没有被实例化是什么原因啊?,谢谢了。
解决方案 »
- 求高人指教,我是C#初学者,想提取txt文件中的内容
- c# ActiveX 与 js交互
- Override引起的疑问!
- 关于获取数据库信息的问题!!!!!!!请高手指点~~~~~~~
- 有没有办法让窗体的keyDown事件先于load事件运行?
- 求救, 我的电脑一装vs2005的sp1就关机,怎么回事啊?
- 怎样检查Request接收的变量中是否有某个变量!??
- 做了一个处理复杂的程序,CPU占有率100%,电脑处于死机状态
- 怎么得到当前目录下,扩展名为.jpg的所有文件?
- C#中 怎么判断一个窗体是否打开
- C# 结构体和数组转化问题
- vs2005怎么写代码的时候数字好像是大写的啊,怎么变成小写啊
string str=(this.listBox1.Items[i] as MyItem).Value;
string titleName = (this.listBox1.Items[i] as MyItem).Text;如果还不行,检查listBox1的Items.Add或DataSource绑定数据的相关代码
{
//若不是第一行则上移
if (ListBox1.SelectedIndex > 0)
{
int index = ListBox1.SelectedIndex;
string temp = ListBox1.Items[index - 1].ToString();
ListBox1.Items[index - 1] = ListBox1.SelectedItem.ToString();
ListBox1.Items[index] = temp;
ListBox1.SelectedIndex = index - 1;
}
}
为什么只要调用这个方法string str=(this.listBox1.Items[i] as MyItemlist).Value;
就说没有被实例化了?急啊,新手求大家帮忙了
这句话不对吧
{
//若不是第一行则上移
if (ListBox1.SelectedIndex > 0)
{
int index = ListBox1.SelectedIndex;
string temp = ListBox1.Items[index - 1].ToString();
ListBox1.Items[index - 1] = ListBox1.SelectedItem.ToString();
ListBox1.Items[index] = temp;
ListBox1.SelectedIndex = index - 1;
}
}
为什么调用这个方法就取不到值
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect > 0)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect - 1, oTempItem);
this.listBox1.SelectedIndex = iselect - 1;
}
这个就能用?大家能帮我分析下嘛?
使用的ToString后,Items[index - 1]不就成引用了个String对象了吗?
然后你再想Items[index - 1] as MyItemlist当然为null了,因为已经不是MyItemlist对象了
你在for循环中把对象从MyItemlist变成了string类型了,需要改为:
int index = ListBox1.SelectedIndex;
object temp = ListBox1.Items[index - 1];
ListBox1.Items[index - 1] = ListBox1.SelectedItem;
ListBox1.Items[index] = temp;
保留原来的类型