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. Change ListView SubItem value

Change ListView SubItem value

Scheduled Pinned Locked Moved C#
comdesignsysadminhostingannouncement
8 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.
  • K Offline
    K Offline
    Kayess Tech
    wrote on last edited by
    #1

    Hi All, I am using a ListView Control to display clients connected to a server. The ListView is set to View.Details and has three columns, 1) Client ID, 2) Client Name 3) Connection Status. What I would like to do is update the 'Connection Status' SubItem to display whether they are connected or disconnected. Can anyone shed any light, thanks. Regards

    Web design and hosting http://www.kayess.com.au

    P 1 Reply Last reply
    0
    • K Kayess Tech

      Hi All, I am using a ListView Control to display clients connected to a server. The ListView is set to View.Details and has three columns, 1) Client ID, 2) Client Name 3) Connection Status. What I would like to do is update the 'Connection Status' SubItem to display whether they are connected or disconnected. Can anyone shed any light, thanks. Regards

      Web design and hosting http://www.kayess.com.au

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You need to work with the SubItems[^] property of a ListViewItem object.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      K 2 Replies Last reply
      0
      • P pmarfleet

        You need to work with the SubItems[^] property of a ListViewItem object.

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        K Offline
        K Offline
        Kayess Tech
        wrote on last edited by
        #3

        Sorry, still can't see how I can do it.

        Web design and hosting http://www.kayess.com.au

        1 Reply Last reply
        0
        • P pmarfleet

          You need to work with the SubItems[^] property of a ListViewItem object.

          Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

          K Offline
          K Offline
          Kayess Tech
          wrote on last edited by
          #4

          Here is what I am trying to do, from what I've read:string search = "x1"; string status = (ConnectionStatus) ? "Connected" : "Disconnected"; int i_row = myListView.Items.IndexOfKey(search); myListView.SelectedItems[i_row].SubItems[3].Text = status;
          However the i_row value returned is always -1

          Web design and hosting http://www.kayess.com.au

          G 1 Reply Last reply
          0
          • K Kayess Tech

            Here is what I am trying to do, from what I've read:string search = "x1"; string status = (ConnectionStatus) ? "Connected" : "Disconnected"; int i_row = myListView.Items.IndexOfKey(search); myListView.SelectedItems[i_row].SubItems[3].Text = status;
            However the i_row value returned is always -1

            Web design and hosting http://www.kayess.com.au

            G Offline
            G Offline
            Gareth H
            wrote on last edited by
            #5

            Kayess Tech, Does your ListView.Items have an item called "x1"? Regards, Gareth.

            K 1 Reply Last reply
            0
            • G Gareth H

              Kayess Tech, Does your ListView.Items have an item called "x1"? Regards, Gareth.

              K Offline
              K Offline
              Kayess Tech
              wrote on last edited by
              #6

              Yes, I have updated from my previous post the ListView items look like this Col 1, Row 1 = Client ID (eg 23) Col 2, Row 1 = Client Name (eg Steve) Col 3, Row 1 = Connection Status (Connected / Disconnected) This is the subitem I want to change programatically. Col 4, Row 1 = Identifier (in this case 'x1') The next Row Identifier would be x2 and so on... Thanks

              "You don't scare me Selene."-Tanis "We'll have to work on that."-Selene (Underworld Evolution)

              D 1 Reply Last reply
              0
              • K Kayess Tech

                Yes, I have updated from my previous post the ListView items look like this Col 1, Row 1 = Client ID (eg 23) Col 2, Row 1 = Client Name (eg Steve) Col 3, Row 1 = Connection Status (Connected / Disconnected) This is the subitem I want to change programatically. Col 4, Row 1 = Identifier (in this case 'x1') The next Row Identifier would be x2 and so on... Thanks

                "You don't scare me Selene."-Tanis "We'll have to work on that."-Selene (Underworld Evolution)

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                It appears your searching your List View Items instead of each item's SubItem. Try something along the lines of this.

                //If i_row is not needed for anything else delete the next line
                int i_row;
                string search = "x1";
                string status = (ConnectionStatus) ? "Connected" : "Disconnected";
                for (int i = 0; i < myListView.Items.Count; i++)
                {
                if (!(myListView.Items[i].SubItems.IndexOfKey(search) == -1))
                {
                //If i_row is not needed for anything else delete the next line
                i_row = i;
                myListView.Items[i].SubItems[3].Text = status;
                break;
                }
                }

                modified on Friday, January 18, 2008 5:53:11 AM

                K 1 Reply Last reply
                0
                • D DaveyM69

                  It appears your searching your List View Items instead of each item's SubItem. Try something along the lines of this.

                  //If i_row is not needed for anything else delete the next line
                  int i_row;
                  string search = "x1";
                  string status = (ConnectionStatus) ? "Connected" : "Disconnected";
                  for (int i = 0; i < myListView.Items.Count; i++)
                  {
                  if (!(myListView.Items[i].SubItems.IndexOfKey(search) == -1))
                  {
                  //If i_row is not needed for anything else delete the next line
                  i_row = i;
                  myListView.Items[i].SubItems[3].Text = status;
                  break;
                  }
                  }

                  modified on Friday, January 18, 2008 5:53:11 AM

                  K Offline
                  K Offline
                  Kayess Tech
                  wrote on last edited by
                  #8

                  Hi, Thanks, but that didn't work either. However I did find a solutionstring search = "x1"; string status = (ConnectionStatus) ? "Connected" : "Disconnected"; for (int i = 0; i < myListView.Items.Count; i++) { { ListViewItem item = myListView.Items; if(item.SubItems[4] == search) items.SubItems[3].Text = status }
                  Thanks all for your suggestions.

                  "You don't scare me Selene."-Tanis "We'll have to work on that."-Selene (Underworld Evolution)

                  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