| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1530 人关注过本帖
标题:listview绑定数据
取消只看楼主 加入收藏
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
结帖率:80.91%
收藏
 问题点数:0 回复次数:0 
listview绑定数据
动态生成listview 可以自定义listview的样式 例如列头颜色 行渐变色等等 这里是像ListView添加数据 以读取数据存放到泛型为例子
//初始化listview
            int x = listView2.Location.X;
            int y = listView2.Location.Y;
            listView2.Clear();
            listView2.Dispose();
            listView2 = new ListView();
            listView2.Refresh();
            listView2.ForeColor = Color.Black;
            listView2.View = View.Details;
            listView2.FullRowSelect = true;
            listView2.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.listView2.GridLines = true;
            this.listView2.OwnerDraw = true;
            this.listView2.Size = new System.Drawing.Size(681, 507);
            this.listView2.Location = new System.Drawing.Point(x, y);


            // 添加列名.
            listView2.Columns.Add("列1", 72, HorizontalAlignment.Center);
            listView2.Columns.Add("列2", 114, HorizontalAlignment.Center);
            listView2.Columns.Add("列3", 135, HorizontalAlignment.Center);
          try
          {
            /*假设读取的数据是存放到泛型list中*/
            for (int i = 0; i < list.Count; i++)
            {
                  ListViewItem listViewItem1 = new ListViewItem(new string[] { list[i].属性1.Trim(),list[i].属性2.Trim(), list[i].属性3.Trim() }, -1);
                  listView2.Items.AddRange(new ListViewItem[] { listViewItem1 });
            }
          }
          catch
          {
          }
            /*也可以考虑给listview2加其他事件*/
            listView2.OwnerDraw = true;
            listView2.DrawItem += new
                DrawListViewItemEventHandler(listView2_DrawItem);
            listView2.DrawSubItem += new
                DrawListViewSubItemEventHandler(listView2_DrawSubItem);
            listView2.DrawColumnHeader += new
                DrawListViewColumnHeaderEventHandler(listView2_DrawColumnHeader);

            listView2.MouseUp += new MouseEventHandler(listView2_MouseUp);

 
            listView2.MouseMove += new MouseEventHandler(listView2_MouseMove);
            listView2.ColumnWidthChanged += new ColumnWidthChangedEventHandler(listView2_ColumnWidthChanged);
            listView2.Invalidated += new InvalidateEventHandler(listView2_Invalidated);
搜索更多相关主题的帖子: 数据 listview 绑定 
2010-10-21 08:29
快速回复:listview绑定数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024804 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved