如何获取listview中被选中的行??

andihuang2008 2006-11-28 01:26:45
如何获取listview中被选中的行??
以及如何获取该行的值!!
高手指点一下吧
...全文
1538 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hq2008 2007-01-27
  • 打赏
  • 举报
回复
good
KJ_Wang 2006-11-28
  • 打赏
  • 举报
回复
人来有一在用程序:设置CheckBoxs=true;

参考一下:
private void cmdRight_Click(object sender, EventArgs e)
{
if (txtGroupID.Text == "")
{
MessageBox.Show("对不起,用户组不能为空!", ConstVariables.SystemInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

ListViewItem item;
for (int ctl = lvLeft.Items.Count - 1; ctl > -1; ctl--)
{
if (lvLeft.Items[ctl].Checked == true)
{
item = new ListViewItem();
item.Text = lvLeft.Items[ctl].Text;
item.SubItems.Add(lvLeft.Items[ctl].SubItems[1].Text);
item.SubItems.Add(DateTime.Now.ToString());
lvRight.Items.Add(item);
lvLeft.Items.RemoveAt(ctl);
}
}
}
KJ_Wang 2006-11-28
  • 打赏
  • 举报
回复
foreach(ListViewItem item in listView1.SelectedItems)

   MessageBox.Show(item.text);
MessageBox.Show(item.SubItems[1].text);
MessageBox.Show(item.SubItems[2].text);
MessageBox.Show(item.SubItems[3].text);
MessageBox.Show(item.SubItems[4].text);
MessageBox.Show(item.SubItems[...].text);


andihuang2008 2006-11-28
  • 打赏
  • 举报
回复
谢谢各位!!!
liujia_0421 2006-11-28
  • 打赏
  • 举报
回复
SelectedItems...
sdl2005lyx 2006-11-28
  • 打赏
  • 举报
回复
foreach(ListViewItem item in listView1.SelectedItems)
{
foreach(ListViewItem.ListViewSubItem subItem in item.SubItems)
{
//subItem 为一行中的子项。
}
}
S.F. 2006-11-28
  • 打赏
  • 举报
回复
foreach(ListViewItem lvi in listView1.SelectedItems)
Console.WriteLine(lvi.Text); //values

110,565

社区成员

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

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

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