补充:在做一个播放器软件。用的listview listview 有2个组 主题和电影
主题下面有:热门电影、经典电影 2个项
电影下面有:喜剧、恐怖、动作、动画 4个项
我想实现单击不同项触发不同事件。想法是判断双击时所选的item的索引
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.listView1.Focus();
if (this.listView1.Items[0].Selected = true)
{
MessageBox.Show("热门电影");
}
else if (this.listView1.Items[1].Selected = true)
{
MessageBox.Show("经典电影");
}
else if (this.listView1.Items[2].Selected = true)
{
MessageBox.Show("喜剧");
}
else if (this.listView1.Items[3].Selected = true)
{
MessageBox.Show("恐怖");
}
else if (this.listView1.Items[4].Selected = true)
{
MessageBox.Show("动作");
}
else if (this.listView1.Items[5].Selected = true)
{
MessageBox.Show("动画");
} }但是运行一直报的是热门电影。不知道那么搞了新手求高手指教!!先感谢!!
PS:麻烦给下例子或者详细注释。。有时候转不过来弯~~~
主题下面有:热门电影、经典电影 2个项
电影下面有:喜剧、恐怖、动作、动画 4个项
我想实现单击不同项触发不同事件。想法是判断双击时所选的item的索引
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.listView1.Focus();
if (this.listView1.Items[0].Selected = true)
{
MessageBox.Show("热门电影");
}
else if (this.listView1.Items[1].Selected = true)
{
MessageBox.Show("经典电影");
}
else if (this.listView1.Items[2].Selected = true)
{
MessageBox.Show("喜剧");
}
else if (this.listView1.Items[3].Selected = true)
{
MessageBox.Show("恐怖");
}
else if (this.listView1.Items[4].Selected = true)
{
MessageBox.Show("动作");
}
else if (this.listView1.Items[5].Selected = true)
{
MessageBox.Show("动画");
} }但是运行一直报的是热门电影。不知道那么搞了新手求高手指教!!先感谢!!
PS:麻烦给下例子或者详细注释。。有时候转不过来弯~~~
listView1.FocusedItem.Text.ToString();
}
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
ListViewHitTestInfo info = listView1.HitTest(e.X, e.Y);
ListViewItem.ListViewSubItem subItem = info.SubItem;
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{ switch(listView1.SelectedIndices[0])
{
case 0:
MessageBox.Show("热门电影");
break;
case 1:
MessageBox.Show("经典电影");
break;
case 2:
MessageBox.Show("喜剧");
break;
case 3:
MessageBox.Show("恐怖"); break;
case 4:
MessageBox.Show("动作");
break;
case 5:
MessageBox.Show("动画");
break;
}
}
}
注意:要确保显示的messgebox内容与你的访问下标的项对应起来
你的意思是双击激活?
listView1.FocusedItem.Text.ToString(); 这句代码的作用不是很懂啊!能详细解释不!
MouseDoubleClick事件中的坐标没搞过啊! subItem是不是就是根据鼠标坐标选取到的子项?
如果是的话那个subItem如何用啊! 求指教啊! 麻烦给给个例子啊!