CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

怎么设置图标(listView)

楼主wjcking()2004-09-04 12:44:21 在 .NET技术 / C# 提问

WinForm,ListView,imagelist  
  程序如下  
  //****************************  
  try  
  {  
  int   intRow;  
  SqlDataAdapter   objAdapter=new   SqlDataAdapter();  
  DataSet   objds=new   DataSet();  
  SqlConnection   objCon=new   SqlConnection(this.strCon);  
  objAdapter.SelectCommand=new   SqlCommand("select   *   from   db_register   order   by   ID   desc",objCon);  
   
  objAdapter.Fill(objds,"db_register");  
  DataTable   objTable=null;  
  objTable=objds.Tables[0];  
  DataRow   objRow=null;  
  this.lvi.Items.Clear();  
   
   
  for(intRow=0;intRow<objTable.Rows.Count;intRow++)  
  {  
  objRow=objTable.Rows[intRow];  
  ListViewItem   lvi=new   ListViewItem();  
   
   
   
  lvi.Text=objRow["UserID"].ToString();  
  lvi.SubItems.Add(objRow["Name"].ToString());  
  lvi.SubItems.Add(objRow[2].ToString());  
  lvi.SubItems.Add(objRow[3].ToString());  
  lvi.SubItems.Add(objRow[4].ToString());  
   
  this.lvi.Items.Add(lvi);  
  }  
  this.lvi.EndUpdate();  
   
   
  }  
  catch(Exception   ex)  
  {  
  MessageBox.Show(ex.ToString());  
  }  
  怎么分别给listView的4中形式设置图标,添加在程序中?   多谢各位 问题点数:20、回复次数:3Top

1 楼wjcking()回复于 2004-09-04 12:52:33 得分 0

还有一个问题,就是怎么给listview里面的某个项设置图标Top

2 楼herony420(坦荡荡)回复于 2004-09-04 14:15:10 得分 20

下面是msdn的例子很好懂,但是请注意是没有办法给subitem设置图标的,这是因为subItem只是设置为显示,而不是控制的  
   
    该示例假定已经将该代码添加到某   Form   中,然后从构造函数或此窗体上的另一个方法调用在该示例中创建的方法。该示例还假定名为   MySmallImage1、MySmallImage2、MyLargeImage1   和   MyLargeImage2   的图像位于驱动器   C   的根目录下。  
   
  [Visual   Basic]    
  Private   Sub   CreateMyListView()  
          '   Create   a   new   ListView   control.  
          Dim   listView1   As   New   ListView()  
          listView1.Bounds   =   New   Rectangle(New   Point(10,   10),   New   Size(300,   200))  
   
          '   Set   the   view   to   show   details.  
          listView1.View   =   View.Details  
          '   Allow   the   user   to   edit   item   text.  
          listView1.LabelEdit   =   True  
          '   Allow   the   user   to   rearrange   columns.  
          listView1.AllowColumnReorder   =   True  
          '   Display   check   boxes.  
          listView1.CheckBoxes   =   True  
          '   Select   the   item   and   subitems   when   selection   is   made.  
          listView1.FullRowSelect   =   True  
          '   Display   grid   lines.  
          listView1.GridLines   =   True  
          '   Sort   the   items   in   the   list   in   ascending   order.  
          listView1.Sorting   =   SortOrder.Ascending  
   
          '   Create   three   items   and   three   sets   of   subitems   for   each   item.  
          Dim   item1   As   New   ListViewItem("item1",   0)  
          '   Place   a   check   mark   next   to   the   item.  
          item1.Checked   =   True  
          item1.SubItems.Add("1")  
          item1.SubItems.Add("2")  
          item1.SubItems.Add("3")  
          Dim   item2   As   New   ListViewItem("item2",   1)  
          item2.SubItems.Add("4")  
          item2.SubItems.Add("5")  
          item2.SubItems.Add("6")  
          Dim   item3   As   New   ListViewItem("item3",   0)  
          '   Place   a   check   mark   next   to   the   item.  
          item3.Checked   =   True  
          item3.SubItems.Add("7")  
          item3.SubItems.Add("8")  
          item3.SubItems.Add("9")  
   
          '   Create   columns   for   the   items   and   subitems.  
          listView1.Columns.Add("Item   Column",   -2,   HorizontalAlignment.Left)  
          listView1.Columns.Add("Column   2",   -2,   HorizontalAlignment.Left)  
          listView1.Columns.Add("Column   3",   -2,   HorizontalAlignment.Left)  
          listView1.Columns.Add("Column   4",   -2,   HorizontalAlignment.Center)  
   
          'Add   the   items   to   the   ListView.  
          listView1.Items.AddRange(New   ListViewItem()   {item1,   item2,   item3})  
   
          '   Create   two   ImageList   objects.  
          Dim   imageListSmall   As   New   ImageList()  
          Dim   imageListLarge   As   New   ImageList()  
   
          '   Initialize   the   ImageList   objects   with   bitmaps.  
          imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage1.bmp"))  
          imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage2.bmp"))  
          imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage1.bmp"))  
          imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage2.bmp"))  
   
          'Assign   the   ImageList   objects   to   the   ListView.  
          listView1.LargeImageList   =   imageListLarge  
          listView1.SmallImageList   =   imageListSmall  
   
          '   Add   the   ListView   to   the   control   collection.  
          Me.Controls.Add(listView1)  
  End   Sub   'CreateMyListView  
   
  [C#]    
  private   void   CreateMyListView()  
  {  
          //   Create   a   new   ListView   control.  
          ListView   listView1   =   new   ListView();  
          listView1.Bounds   =   new   Rectangle(new   Point(10,10),   new   Size(300,200));  
   
          //   Set   the   view   to   show   details.  
          listView1.View   =   View.Details;  
          //   Allow   the   user   to   edit   item   text.  
          listView1.LabelEdit   =   true;  
          //   Allow   the   user   to   rearrange   columns.  
          listView1.AllowColumnReorder   =   true;  
          //   Display   check   boxes.  
          listView1.CheckBoxes   =   true;  
          //   Select   the   item   and   subitems   when   selection   is   made.  
          listView1.FullRowSelect   =   true;  
          //   Display   grid   lines.  
          listView1.GridLines   =   true;  
          //   Sort   the   items   in   the   list   in   ascending   order.  
          listView1.Sorting   =   SortOrder.Ascending;  
                                   
          //   Create   three   items   and   three   sets   of   subitems   for   each   item.  
          ListViewItem   item1   =   new   ListViewItem("item1",0);  
          //   Place   a   check   mark   next   to   the   item.  
          item1.Checked   =   true;  
          item1.SubItems.Add("1");  
          item1.SubItems.Add("2");  
          item1.SubItems.Add("3");  
          ListViewItem   item2   =   new   ListViewItem("item2",1);  
          item2.SubItems.Add("4");  
          item2.SubItems.Add("5");  
          item2.SubItems.Add("6");  
          ListViewItem   item3   =   new   ListViewItem("item3",0);  
          //   Place   a   check   mark   next   to   the   item.  
          item3.Checked   =   true;  
          item3.SubItems.Add("7");  
          item3.SubItems.Add("8");  
          item3.SubItems.Add("9");  
   
          //   Create   columns   for   the   items   and   subitems.  
          listView1.Columns.Add("Item   Column",   -2,   HorizontalAlignment.Left);  
          listView1.Columns.Add("Column   2",   -2,   HorizontalAlignment.Left);  
          listView1.Columns.Add("Column   3",   -2,   HorizontalAlignment.Left);  
          listView1.Columns.Add("Column   4",   -2,   HorizontalAlignment.Center);  
   
          //Add   the   items   to   the   ListView.  
                          listView1.Items.AddRange(new   ListViewItem[]{item1,item2,item3});  
   
          //   Create   two   ImageList   objects.  
          ImageList   imageListSmall   =   new   ImageList();  
          ImageList   imageListLarge   =   new   ImageList();  
   
          //   Initialize   the   ImageList   objects   with   bitmaps.  
          imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));  
          imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));  
          imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));  
          imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));  
   
          //Assign   the   ImageList   objects   to   the   ListView.  
          listView1.LargeImageList   =   imageListLarge;  
          listView1.SmallImageList   =   imageListSmall;  
   
          //   Add   the   ListView   to   the   control   collection.  
          this.Controls.Add(listView1);  
  }  
  Top

3 楼ffb(项目急,顾不了结构的)回复于 2004-09-16 17:13:44 得分 0

SubItem的图标怎么加?Top

相关问题

  • 图标和字体怎么设置啊?
  • listview怎么显示大图标??
  • 图标设置?
  • ListView中各个图标之间的间距怎样设置?
  • listview中不想显示图标,应如何设置才安全?
  • listview图标---ShGetFileInfo
  • 如何在程序里面设置和更改的listview内各项图标???
  • ListView图标大小
  • ListView 图标问题 ?
  • 对话框怎么没有地方设置图标呀?

关键词

  • db
  • null
  • introw
  • objds
  • objadapter
  • listview
  • objcon
  • objtable
  • sqldataadapter
  • sqlconnection

得分解答快速导航

  • 帖主:wjcking
  • herony420

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo