高手求救!!急 我唯一得80分都给了!

victorzc 2004-08-26 03:50:00
我想获得listview单击每一行的index 高手们多多指教!!!
...全文
118 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
The123 2004-08-26
  • 打赏
  • 举报
回复
listView1.SelectedItems[0].Index.ToString();
注意判断SelectedItems
happyno7 2004-08-26
  • 打赏
  • 举报
回复
// 用SelectedIndices

private void ListView1_SelectedIndexChanged_UsingIndices(
object sender, System.EventArgs e)
{

ListView.SelectedIndexCollection indexes =
this.ListView1.SelectedIndices;

double price = 0.0;
foreach ( int index in indexes )
{
price += Double.Parse(
this.ListView1.Items[index].SubItems[1].Text);
}

// Output the price to TextBox1.
TextBox1.Text = price.ToString();
}
jimh 2004-08-26
  • 打赏
  • 举报
回复
如果客户端代码,realljx(至尊十三少-抵制日货(For ever)) 已经回答了,如果是客户端代码,可能麻烦一点,先加上一个函数function ItemClick(index),然后在每一行里加上onclick事件,参数就是该行的index了。
chNET 2004-08-26
  • 打赏
  • 举报
回复
你是什么意思呀?
是这个吗?
private void listView1_Click(object sender, System.EventArgs e)
{
if(listView1.SelectedItems.Count == 1)
{
MessageBox.Show(listView1.SelectedItems[0].Index.ToString());
}
}

happyno7 2004-08-26
  • 打赏
  • 举报
回复
private void ListView1_SelectedIndexChanged_UsingItems(
object sender, System.EventArgs e)
{

ListView.SelectedListViewItemCollection breakfast =
this.ListView1.SelectedItems;

double price = 0.0;
foreach ( ListViewItem item in breakfast )
{
price += Double.Parse(item.SubItems[1].Text);
}

// Output the price to TextBox1.
TextBox1.Text = price.ToString();
}
victorzc 2004-08-26
  • 打赏
  • 举报
回复
不行呀 我刚才试了
realljx 2004-08-26
  • 打赏
  • 举报
回复

              foreach(ListViewItem lv in listView1.SelectedItems)
{
lv.Index; //这个就是。
}
realljx 2004-08-26
  • 打赏
  • 举报
回复
你都是高手 你还求救什么啊?

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧