winform中的listview

zteclx 2010-01-02 04:10:23
对listview还不太明白,其中的item和subitem是什么含义?好像还有item[0],item[1];subitem[0]等?
现在要做的是把sqlserver数据库中的记录添加到listview中,大家有用过吗?
...全文
62 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
米洛尔 2012-04-18
  • 打赏
  • 举报
回复
我们最近做的全是逐行添加进去的,就是增删改查其中的查询吧
liyajie865808403 2012-02-12
  • 打赏
  • 举报
回复
这样选中一行


有个属性:FullRowSelect改为true就可以了
zteclx 2010-01-02
  • 打赏
  • 举报
回复
3楼的办法可以了。现在还有个问题:
使用鼠标点击时不能选中一行,只能选中一行中的一列。如何才能选中整行呢(就是让一行高亮)?
flyerwing 2010-01-02
  • 打赏
  • 举报
回复
好象不能直接绑定只能循环添加上去吧
例如:
for(int i=0;i<dt.rows.count;++i)
{
ListViewItem item=new ListViewItem();
item.Text=dt.rows[i]["name"];
ListViewSubItem sub=ListViewSubItem();
sub.Text=dt.rows[i]["content"];
item.SubItems.Add(sub);
ListView1.Items.Add(item);
}
wuyq11 2010-01-02
  • 打赏
  • 举报
回复
Items 获取包含控件中所有项的集合
item[0],的一行
using(SqlConnection con= new SqlConnection(""))
{
con.Open();
DataSet dst = new DataSet();
SqlCommand cmd =new SqlCommand ("select id from Tb",con );
SqlDataAdapter dap = new SqlDataAdapter(cmd);
dap.Fill(dst);
con.Close();
this.listView1.Columns.Add("ID编号", 80, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.GridLines = true;
string[] str = new string[1];
foreach (DataRow row in dst.Tables[0].Rows)
{
str[0] = row["id"].ToString();
ListViewItem item = new ListViewItem(str, 0);
listView1.Items.Add(item);
}
}
zteclx 2010-01-02
  • 打赏
  • 举报
回复
能提供从数据库中取出记录加到listview中的代码吗?
flyerwing 2010-01-02
  • 打赏
  • 举报
回复
item第一列,SUBITEM是一行的子列

110,567

社区成员

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

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

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