如图,数据是从数据库中加载的,选中的项背景变色,默认的ListView实现不了边框,而且选中后背景只突出显示图片和文字,背景颜色还是改变不了。
有什么办法显示每项的边框线,并且选中后整个背景变色,并不是只有文字和图标变色,或者有没有这样的第三方控件?

解决方案 »

  1.   

    参考代码:
    this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
                listViewItem1,
                listViewItem2,
                listViewItem3});
                this.listView1.LargeImageList = this.imageList1;
                this.listView1.Location = new System.Drawing.Point(67, 63);
                this.listView1.Name = "listView1";
                this.listView1.OwnerDraw = true;
                this.listView1.Size = new System.Drawing.Size(282, 264);
                this.listView1.TabIndex = 0;
                this.listView1.UseCompatibleStateImageBehavior = false;
                this.listView1.DrawItem += new System.Windows.Forms.DrawListViewItemEventHandler(this.listView1_DrawItem); private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
            {
                Pen p = new Pen(Color.Black);
                e.Graphics.DrawRectangle(p, e.Bounds);            Rectangle fill = new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2);
                if (e.Item.Selected)
                {
                    Pen bg = new Pen(Color.AliceBlue);
                    e.Graphics.FillRectangle(bg.Brush, fill);
                }            Rectangle rp = new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 5, e.Bounds.Width - 10, e.Bounds.Height - 20);
                e.Graphics.DrawImage(this.imageList1.Images[1], rp);
              
                e.Graphics.DrawString(e.Item.Text, this.Font, p.Brush, e.Bounds.X + 5, e.Bounds.Y + e.Bounds.Height - 15);        }
      

  2.   

    这些代码好像不能实现上面的效果,中间会有空行,有什么办法让ListView显示出表格线来?
      

  3.   

    listView1.GridLines = true;//显示网格线