日期:2014-05-19  浏览次数:21283 次

高手们啊!十万火急!帮帮忙啊!关于LISTVIEW的显示问题
我做了FORM来显示LISTVIEW,当不加载InitializeComponent();时,可以正确显示表中的内容,但是一加载InitializeComponent();时,就成白板了,高手们,这是什么原因啊!

using   System;
using   System.Drawing;
using   System.Collections;
using   System.ComponentModel;
using   System.Windows.Forms;
using   System.Data;
using   System.Data.OleDb;

namespace   WEFSINFO
{
public   class   frmlistv:   Form  
{   //   定义数据连接的字符串  

private   System.Windows.Forms.ListView   lv;
Database   data   =   new   Database();
//private   ListView   lv;

private   void   InitializeComponent()
{
this.lv   =   new   System.Windows.Forms.ListView();
this.SuspendLayout();
//  
//   lv
//  
this.lv.Dock   =   System.Windows.Forms.DockStyle.Fill;
this.lv.Location   =   new   System.Drawing.Point(0,   0);
this.lv.MultiSelect   =   false;
this.lv.Name   =   "lv ";
this.lv.Size   =   new   System.Drawing.Size(584,   387);
this.lv.TabIndex   =   0;
//  
//   frmlistv
//  
this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);
this.ClientSize   =   new   System.Drawing.Size(584,   387);
this.Controls.Add(this.lv);
this.Name   =   "frmlistv ";
this.ResumeLayout(false);

}
 


//public   frmlistv(DPControls.Controls.WFrame   wFrame)  
public   frmlistv()  
{  
//
//   Required   for   Windows   Form   Designer   support
//
InitializeComponent();

//
//   TODO:   Add   any   constructor   code   after   InitializeComponent   call
//
Vlist();

}  

[STAThread]
static   void   Main()  
{
Application.Run(new   frmlistv());
}

void   Vlist()
{
data.Open();

this.Left   =   0;  
this.Top   =   0;  
this.Text   =   "在ListView中显示数据库内容! ";  

//   初始化ListView  
lv   =   new   ListView();  
lv.Left   =   0;  
lv.Top   =   0;  
lv.Width   =   700;  
lv.Height   =   this.ClientRectangle.Height;  
lv.GridLines   =   true; //显示各个记录的分隔线  
lv.FullRowSelect   =   true; //   要选择就是一行  
lv.View   =   View.Details; //   定义列表显示的方式  
lv.Scrollable   =   true; //   需要时候显示滚动条  
lv.MultiSelect   =   false; //   不可以多行选择  
lv.HeaderStyle   =   ColumnHeaderStyle.Nonclickable;  
//   针对数据库的字段名称,建立与之适应显示表头  
lv.Columns.Add   ( "姓名 ",60,HorizontalAlignment.Right);  
lv.Columns.Add   ( "住宅电话 ",100,HorizontalAlignment.Left);  
lv.Columns.Add   ( "办公电话 ",100,HorizontalAlignment.Left);  

lv.Visible   =   true;  

OleDbDataReader   reader;