程序是这样写的:
ListBoxItem newItem = new ListBoxItem();
newItem.Content = news[i];
newItem.Tag = newItems[i];
this.listBox1.Items.Add(newItem); 显示:
MessageBox.Show(listBox1.Items[listBox1.SelectedIndex].ToString());
ListBoxItem newItem = new ListBoxItem();
newItem.Content = news[i];
newItem.Tag = newItems[i];
this.listBox1.Items.Add(newItem); 显示:
MessageBox.Show(listBox1.Items[listBox1.SelectedIndex].ToString());
解决方案 »
- 急急急,求教,MC3000的扫描键的keyvalue
- 注册表中为什么读取不到 Adobe Flash Player ActiveX 这个键?
- 怎么“实体类”不用加“DataContract”、“DataMember”
- 大家有人用过reportbuilder吗?.net上有类似的控件吗?
- vs.net中的textbox控件,在鼠标 按下光标总是最前面,无法地位到想要的位置
- 得到局域网内的计算机ip和计算机名
- winfrm中嵌入html代码
- 简单问题,怎么样在listView控件中添加checkbox列!急
- 紧急求助!
- 我想知道如何打印水晶报表???
- winform中datagridview导出excel问题
- 网页设计问题
{
public string Content
{
get;
set;
}
public string Tag { get; set; } public override string ToString()
{
return this.Tag;
}
}
上面是看你的代码猜的..只要在ListBoxItem类里面重写 ToString()方法就行
或者:
MessageBox.Show(((ListBoxItem)(listBox1.SelectedItem)).Content);
public override string ToString()
{
return this.Tag;//要显示Content的话就是 return this.Content;
}
ok?
//绑定数据
List<string> st = new List<string>();
st.Add("conteng1");
st.Add("conteng2");
listBox1.ItemsSource = st;//触发事件
string a = listBox1.Items[listBox1.SelectedIndex].ToString();
MessageBox.Show(a); 这样就可以显示你想要的结果了