Listview??

This is a discussion on Listview?? within the C# Programming forums, part of the General Programming Boards category; Hi, I've got a stupid problem: I want to show the column header in a listview, but I really can't ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    Listview??

    Hi, I've got a stupid problem:
    I want to show the column header in a listview, but I really can't figure out what is wrong with it. I can't work it though

    here is the simple code, only one listview on the form:

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

    namespace listview
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.ListView listView1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();
    listview();
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.listView1 = new System.Windows.Forms.ListView();
    this.SuspendLayout();
    //
    // listView1
    //
    this.listView1.Location = new System.Drawing.Point(200, 48);
    this.listView1.Name = "listView1";
    this.listView1.Size = new System.Drawing.Size(432, 144);
    this.listView1.TabIndex = 0;
    //
    // Form1
    //
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(688, 365);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
    this.listView1});
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {

    Application.Run(new Form1());

    }

    private void listview()
    {
    ListView listView1 = new ListView();
    listView1.Columns.Add("column",-2, HorizontalAlignment.Left);


    }
    }
    }


    Please help me, thanx
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    Please use code tags next time.

    You already have a listview. Make sure in the designer that the style of the listview is "Report" or something like that. Try each style until you see Columns. You can add columns and data with the designer. If you want to do it with code, you have to use the listview of the form you already made with the designer:

    ListView listView1 = new ListView();

    This line creates a local variable listView1 and thereby hides your listView1 of your form. The ListView is already there, no need to recreate it.

    listView1.Columns.Add("column",-2, HorizontalAlignment.Left);

    This should work.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    thank you,nvoigt!

    I found that the item in listview is uneditable, is there any example or article about this problem?

    thanx!!
    Don't laugh at me,I am just a SuperNewbie.

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    It's editable in code and in the designer. If you need it to be editable by users, maybe a grid is the better choice.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    Unhappy

    thanx again, another problem about listview property. if there are some columns in the listview and I want to set the column size fixed, which property is it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListView Refresh, Update
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2006, 08:13 AM
  2. Replies: 6
    Last Post: 07-10-2006, 12:05 AM
  3. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 12:26 AM
  4. Listview with c/c++
    By X PaYnE X in forum Windows Programming
    Replies: 8
    Last Post: 03-20-2005, 10:29 PM
  5. ListView 6.0 OnListItemClick Problem
    By blundstrom in forum Windows Programming
    Replies: 1
    Last Post: 07-21-2002, 11:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21