listview 取值

zzxxdd 2009-10-30 10:09:48
listview中知道选中的行号

也知道了选中的列的列名

如何修改该行该列的值?

列1 列2 列3
行1 a b c
行2 a2 b2 c2
行3 a3 b3 c3

就是说我如果选择了行3,也知道了现在点击的是列2,我怎么把b3这个值修改为别的什么值
...全文
102 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzxxdd 2009-10-30
  • 打赏
  • 举报
回复
谢谢~~~
Hamsic 2009-10-30
  • 打赏
  • 举报
回复
if (lv_Sell.Items.Count != 0)
{
for (int i = 0; i <= lv_Sell.Items.Count - 1; i++)
{
if (lv_Sell.Items[i].Selected)
{
ListViewItem lv = lv_Sell.Items[i];
string a = lv.SubItems[4].Text.ToString();//SubItems[] []中填需要获取的列
break;
}
}
}
h_w_king 2009-10-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zzxxdd 的回复:]
或者请教  我如何获取选中列  的  列号  呢?
[/Quote]
用循环找


private int getindex(string s)
{
foreach (ColumnHeader c in this.listView1.Columns)
{
if (c.Text == s)
return c.Index;
}
return -1;
}



int t = getindex("列2");
if (t >= 0)
this.listView1.Items[2].SubItems[t].Text = "ppp";
wuyq11 2009-10-30
  • 打赏
  • 举报
回复
if(listView1.SelectedItems.Count > 0)
{
this.listView1.SelectedItems[0].Tag.ToString();
this.listView1.SelectedItems[0].SubItems[1].Text ;
this.listView1.SelectedItems[0].SubItems[2].Text;
}
zzxxdd 2009-10-30
  • 打赏
  • 举报
回复
或者请教 我如何获取选中列 的 列号 呢?
zzxxdd 2009-10-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 h_w_king 的回复:]
this.listView1.Items[2].SubItems[1].Text = "ppp";
[/Quote]


我现在不知道列号,只知道列的名字

就是说我不知道 subItems[1]中的1啊,我只能知道 "列2"
h_w_king 2009-10-30
  • 打赏
  • 举报
回复
this.listView1.Items[2].SubItems[1].Text = "ppp";

110,570

社区成员

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

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

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