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. ListView in C#

ListView in C#

Scheduled Pinned Locked Moved C#
csharpdata-structuresxmlhelpquestion
25 Posts 5 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.
  • M mrithula8

    Hi It tells that 1 is not valid argument index.

    K Offline
    K Offline
    King Julien
    wrote on last edited by
    #21

    how many column headers you have??? because the subitems index always starts from 0. can you post the entire code block of the listcontrol??? if possible...

    Have a Happy Coding.....

    M 2 Replies Last reply
    0
    • K King Julien

      how many column headers you have??? because the subitems index always starts from 0. can you post the entire code block of the listcontrol??? if possible...

      Have a Happy Coding.....

      M Offline
      M Offline
      mrithula8
      wrote on last edited by
      #22

      Hi I have created 3 column headers

      private void CreateHeadersAndFillListView()
      {
      colHead = new ColumnHeader();
      colHead.Text = "Servers";
      colHead.Width = 250;
      listView1.Columns.Add(colHead);

              colHead = new ColumnHeader();
              colHead.Text = "Status";
              colHead.Width = 100;
              listView1.Columns.Add(colHead);
      
              colHead = new ColumnHeader();
              colHead.Text = "Last accessed";
              colHead.Width = 100;
              listView1.Columns.Add(colHead);
      
      
          }
      
          private void PaintList(String sss)
          {
              try
              {
                  
                  //ListViewItem.ListViewSubItem lvsi;
                  reader = new XmlTextReader("path.xml");
      
                  while (reader.Read())
                  {
                      switch (reader.NodeType)
                      {
                          case XmlNodeType.Text: //Display the text in each element.
                              //   Console.WriteLine(reader.Value);
                              String s1;
                              s1 = reader.Value;
                              String ss;
                              ss = listBox4.SelectedItem.ToString();
                              sss = ss + s1;
                              object o3 = (object)sss;
                              //String s = (string)o3;
                              //listBox2.Items.Add(o3);
      
                              DirectoryInfo dire = new DirectoryInfo(sss);
                              if (dire.Exists)
                              {
                                  String\[\] folder;
                                  folder = Directory.GetDirectories(sss);
                                  foreach (string foldername in folder)
                                  {
                                      DirectoryInfo di = new DirectoryInfo(foldername);
                                      if (di.Exists)
                                      {
                                          String\[\] files;
                                          files = Directory.GetFiles(foldername,"\*.exe\*");
      
                                          foreach (String filename in files)
                                          {
                                              lvi = new ListViewItem();
                                              lvi.Text = filename;
                                              listView1.Items.Add(lvi);
      
      1 Reply Last reply
      0
      • K King Julien

        how many column headers you have??? because the subitems index always starts from 0. can you post the entire code block of the listcontrol??? if possible...

        Have a Happy Coding.....

        M Offline
        M Offline
        mrithula8
        wrote on last edited by
        #23

        Hi, If i add subitem like the following it just gives the subitem "Started" corresponding to every item in listview.But what i require is that when the server starts it must display the subitem "Started.." to the corresponding item (server) that has started.

        DirectoryInfo di = new DirectoryInfo(foldername);
        if (di.Exists)
        {
        String[] files;
        files = Directory.GetFiles(foldername,"*.exe*");

                                            foreach (String filename in files)
                                            {
                                                lvi = new ListViewItem();
                                                lvi.Text = filename;
                                                listView1.Items.Add(lvi);
        
                                                lvi = new ListViewItem();
                                                lvi.SubItems.Add("Started..");
                                                listView1.Items.Add(lvi);                                                                             
        
                                            }
                                            this.Controls.Add(listView1);
        
        K 1 Reply Last reply
        0
        • M mrithula8

          Hi, If i add subitem like the following it just gives the subitem "Started" corresponding to every item in listview.But what i require is that when the server starts it must display the subitem "Started.." to the corresponding item (server) that has started.

          DirectoryInfo di = new DirectoryInfo(foldername);
          if (di.Exists)
          {
          String[] files;
          files = Directory.GetFiles(foldername,"*.exe*");

                                              foreach (String filename in files)
                                              {
                                                  lvi = new ListViewItem();
                                                  lvi.Text = filename;
                                                  listView1.Items.Add(lvi);
          
                                                  lvi = new ListViewItem();
                                                  lvi.SubItems.Add("Started..");
                                                  listView1.Items.Add(lvi);                                                                             
          
                                              }
                                              this.Controls.Add(listView1);
          
          K Offline
          K Offline
          King Julien
          wrote on last edited by
          #24

          So you finally got that....!!! Hail Hurray!!! If you want to show the status dynamically, then you need to go for threading..... Dedicate a thread specifically for updates and things will work...

          Have a Happy Coding.....

          M 1 Reply Last reply
          0
          • K King Julien

            So you finally got that....!!! Hail Hurray!!! If you want to show the status dynamically, then you need to go for threading..... Dedicate a thread specifically for updates and things will work...

            Have a Happy Coding.....

            M Offline
            M Offline
            mrithula8
            wrote on last edited by
            #25

            Hi I tried with the following code. It displays "Started" as a subitem for the 2nd item in listview control

            lvsi = new ListViewItem.ListViewSubItem();
            lvsi.Text = "Started..";
            //lvi.SubItems.Add(lvsi);
            listView1.Items[1].SubItems.Insert(1, lvsi);

            If i use

            listView1.Items[0].SubItems.Insert(0, lvsi);

            it displys "started " as an item and not a subitem like Server status Last accessed started Server1.exe ... .... Can you give me some suggestions

            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