private void button2_Click(object sender, System.EventArgs e)
{
                            listView1.View = View.Details;
  listView1.Columns.Add("first column",60,HorizontalAlignment.Center);
listView1.Columns.Add("second column",60,HorizontalAlignment.Center);
ColumnHeader h = new ColumnHeader();
h.Text = "third column";
h.Width = 60;
h.TextAlign = HorizontalAlignment.Center;
listView1.Columns.Add(h);
ListViewItem lvi = new ListViewItem("haha");
lvi.SubItems.Add("xixi");
lvi.SubItems.Add("ddd");
listView1.Items.Add(lvi);
}

解决方案 »

  1.   

    listView1.View = View.Details;//这个是必须的
      

  2.   

    如果我把Form1_Load其他的代码都注释掉了就可以正常显示
                               /*this.treeView1 .BeginUpdate() ;
    this.treeView1 .Nodes .Add ("我的任务");
    this.treeView1 .Nodes .Add ("所有文档");
    this.treeView1 .Nodes[0].Nodes .Add ("修改文档");
    this.treeView1 .Nodes[0].Nodes .Add ("提交审核");
    this.treeView1 .Nodes[0].Nodes .Add ("提交回复");
    // 定义数据库连接
    SqlConnection conn = new SqlConnection();
    //初始化连接字符串
    conn.ConnectionString= "data source=soft-ronan;initial catalog=DMS;persist security info=False;user id=sa;Password=lijihui;";
    conn.Open();
    //添加命令,从数据库中得到数据
    SqlCommand sqlCmd= new SqlCommand();
    sqlCmd.Connection = conn;
    sqlCmd.CommandText = "select * from project";
    sqlCmd.CommandType = CommandType.Text ;
    SqlDataAdapter adp = new SqlDataAdapter(sqlCmd);
    adp.Fill(ds);

    conn.Close();

    //调用递归函数,完成树形结构的生成
    AddTree(0, (TreeNode)null);
    this.treeView1 .EndUpdate ();*/
      

  3.   

    建立一个新函数,把treeview生成树放到新函数,然后在Form1_Load中调用即可
    public void creatSubTree()
    {
    // 定义数据库连接
    SqlConnection conn = new SqlConnection();
    //初始化连接字符串
    conn.ConnectionString= "data source=soft-ronan;initial catalog=DMS;persist security info=False;user id=sa;Password=lijihui;";
    conn.Open();
    //添加命令,从数据库中得到数据
    SqlCommand sqlCmd= new SqlCommand();
    sqlCmd.Connection = conn;
    sqlCmd.CommandText = "select * from project";
    sqlCmd.CommandType = CommandType.Text ;
    SqlDataAdapter adp = new SqlDataAdapter(sqlCmd);
    adp.Fill(ds);

    conn.Close();

    //调用递归函数,完成树形结构的生成
    AddTree(0, (TreeNode)null);
    this.treeView1 .EndUpdate ();
    }