public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("aa");
dt.Columns.Add("bb");
for (int i = 0; i < 10; i++)
{
dt.Rows.Add("aa" + i, "bb" + i);
}
dt.AcceptChanges();
this.listBox1.DisplayMember = "bb";
this.listBox1.DataSource = dt;
this.listBox1.Height = 200;
this.listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_MouseDoubleClick);
}
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = this.listBox1.IndexFromPoint(e.Location);
if (index != System.Windows.Forms.ListBox.NoMatches)
{
MessageBox.Show(index.ToString());
//do your stuff here
}
}
}
参考链接:
http://bbs.csdn.net/topics/350051564
本文转自daniel8294 51CTO博客,原文链接:http://blog.51cto.com/acadia627/1700718,如需转载请自行联系原作者