Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. adding column in a listview

adding column in a listview

Scheduled Pinned Locked Moved C#
csharphelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TAFIN
    wrote on last edited by
    #1

    hey!! im in a prob.i am trying to add some column and items in a list view. but cant add a column even.Here is a code snippet. i am novice in C#. plz help. Thanks in advance. TANIM Bangladesh

    private void Form1_Load(object sender, EventArgs e)
    {

            ColumnHeader columnHeader1 = new ColumnHeader();
            //columnHeader1.Text = "TANIM";
            listView1.Columns.Add(columnHeader1);
            //listView1.Columns.Add("TANIM", -2, HorizontalAlignment.Left);
            
           
        }
    
    A M T C 4 Replies Last reply
    0
    • T TAFIN

      hey!! im in a prob.i am trying to add some column and items in a list view. but cant add a column even.Here is a code snippet. i am novice in C#. plz help. Thanks in advance. TANIM Bangladesh

      private void Form1_Load(object sender, EventArgs e)
      {

              ColumnHeader columnHeader1 = new ColumnHeader();
              //columnHeader1.Text = "TANIM";
              listView1.Columns.Add(columnHeader1);
              //listView1.Columns.Add("TANIM", -2, HorizontalAlignment.Left);
              
             
          }
      
      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Try This

      listView1.View = View.Details;
      listView1.Columns.Add("Column Name", 50, HorizontalAlignment.Left);

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      1 Reply Last reply
      0
      • T TAFIN

        hey!! im in a prob.i am trying to add some column and items in a list view. but cant add a column even.Here is a code snippet. i am novice in C#. plz help. Thanks in advance. TANIM Bangladesh

        private void Form1_Load(object sender, EventArgs e)
        {

                ColumnHeader columnHeader1 = new ColumnHeader();
                //columnHeader1.Text = "TANIM";
                listView1.Columns.Add(columnHeader1);
                //listView1.Columns.Add("TANIM", -2, HorizontalAlignment.Left);
                
               
            }
        
        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Along with Abhijits answer you need to be aware that the SubItems need to be added for each item. It is possible to have say 5 columns and only 3 subitems for an item. The missing subitems are null and may generate an exception.

        1 Reply Last reply
        0
        • T TAFIN

          hey!! im in a prob.i am trying to add some column and items in a list view. but cant add a column even.Here is a code snippet. i am novice in C#. plz help. Thanks in advance. TANIM Bangladesh

          private void Form1_Load(object sender, EventArgs e)
          {

                  ColumnHeader columnHeader1 = new ColumnHeader();
                  //columnHeader1.Text = "TANIM";
                  listView1.Columns.Add(columnHeader1);
                  //listView1.Columns.Add("TANIM", -2, HorizontalAlignment.Left);
                  
                 
              }
          
          T Offline
          T Offline
          TAFIN
          wrote on last edited by
          #4

          Thanks!!!:thumbsup:

          1 Reply Last reply
          0
          • T TAFIN

            hey!! im in a prob.i am trying to add some column and items in a list view. but cant add a column even.Here is a code snippet. i am novice in C#. plz help. Thanks in advance. TANIM Bangladesh

            private void Form1_Load(object sender, EventArgs e)
            {

                    ColumnHeader columnHeader1 = new ColumnHeader();
                    //columnHeader1.Text = "TANIM";
                    listView1.Columns.Add(columnHeader1);
                    //listView1.Columns.Add("TANIM", -2, HorizontalAlignment.Left);
                    
                   
                }
            
            C Offline
            C Offline
            carlecomm
            wrote on last edited by
            #5

            Give this a try: ListViewItem lst1 = new ListViewItem(str, 0); listView1.Items.Add(lst1);

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups