添加item的时候设置tag属性,它是个object类型的属性;item.Tag=网址;
解决方案 »
- 底层HTTP协议通信问题
- 跪求快速输入代码的方法
- 用smtpClient发送E_Mail的问题?为什么总是超时,问题在哪?
- Enterprise Library January 2006使用问题
- 關於DataGrid中的CheckBox的問題(WinForm)
- 如何在打开网站时自定义IE的大小?
- 请问在VS.net中建立扩展存储过程,只能用C++吗?C#不行吗?
- 为什么换不了行?
- 用jmail如何判断接收到邮件的状态(已读\未读)
- 甩分求解,VS的项目属性如何自定义添加一个tab,实现立刻给分
- visual studio 2012 添加连接的问题
- WPF,请问如何让表里的Header绑定变量?
我是想鼠标点击某item后输出对应的字母,比如鼠标点击数字4就msgbox输出d,十分感谢。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace Listbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void listBox1_Click(object sender, EventArgs e)
{
MessageBox.Show(listBox1.SelectedItem.ToString());
} private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 26; i++)
{
this.listBox1.Items.Add(i);
}
}
}
}
看这个方法貌似更简单些,求大神指点啊
for (int i = 1; i <= 26; i++)
{
ListBoxItem item = new ListBoxItem ();
item.Tag ="i";
this.listBox1.Items.Add(i);
}至于你第二个问题,你先去了解什么是ListBox控件,什么是ListBoxItem
求给个完整的例子,万分感激
object是什么这个我就不再教育了。
自定义一个类 public class MyProperty {
public string _showtext;
public string _showurl;
public string showtext { get{return _showtext;} set{_showtext=value;} }
public string showurl { get{return _showurl;} set{_showurl=value;} }
public override string ToString()
{
return _showtext;
}
}后这样做:for (int i = 1; i <= 26; i++)
{
MyProperty item = new MyProperty ();
item.showtext ="i";
item.showurl =url+"i";
this.listBox1.Items.Add(i);
}
读取的时候这样做:
string url= ((MyProperty)listbox1.items[0]).showurl;
下面这个累也适用吗?谢谢。
无法将类型为“System.String”的对象强制转换为类型“webclient.MyProperty”。希望楼上老兄解答下哦,感谢
object ob=NewsList.Items[0];
string url=((MyProperty)ob).showurl