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 - Select ListViewItem

ListView - Select ListViewItem

Scheduled Pinned Locked Moved C#
tutorialquestion
11 Posts 6 Posters 1 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.
  • A Offline
    A Offline
    al3xutzu00
    wrote on last edited by
    #1

    Hi, I have a list view with 5 columns and 4 items in that listView. When i click on a row ( item) of that listViewi want the whole row to be highlighted blue , and if i select another row, what that it to be selected as well. So basically i want it to look like the whole row is selected not just the first column item. here is what i tried : private void listView1_Click(object sender, EventArgs e) { for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Selected == true) { listView1.Items[i].BackColor = Color.Blue; } } } BUT this works after I change the selection of the row! for example i select row 1 , and when i select row 2 , then row 1 is highlited . Why guys? Any suggestions please? Regards, Alex

    “Be the change you want to see in the world.”

    N F CPalliniC D 4 Replies Last reply
    0
    • A al3xutzu00

      Hi, I have a list view with 5 columns and 4 items in that listView. When i click on a row ( item) of that listViewi want the whole row to be highlighted blue , and if i select another row, what that it to be selected as well. So basically i want it to look like the whole row is selected not just the first column item. here is what i tried : private void listView1_Click(object sender, EventArgs e) { for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Selected == true) { listView1.Items[i].BackColor = Color.Blue; } } } BUT this works after I change the selection of the row! for example i select row 1 , and when i select row 2 , then row 1 is highlited . Why guys? Any suggestions please? Regards, Alex

      “Be the change you want to see in the world.”

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Learn to edit a post or learn what 'FOAD' stands for.


      Panic, Chaos, Destruction. My work here is done.

      A 1 Reply Last reply
      0
      • A al3xutzu00

        Hi, I have a list view with 5 columns and 4 items in that listView. When i click on a row ( item) of that listViewi want the whole row to be highlighted blue , and if i select another row, what that it to be selected as well. So basically i want it to look like the whole row is selected not just the first column item. here is what i tried : private void listView1_Click(object sender, EventArgs e) { for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Selected == true) { listView1.Items[i].BackColor = Color.Blue; } } } BUT this works after I change the selection of the row! for example i select row 1 , and when i select row 2 , then row 1 is highlited . Why guys? Any suggestions please? Regards, Alex

        “Be the change you want to see in the world.”

        F Offline
        F Offline
        fly904
        wrote on last edited by
        #3

        al3xutzu00 wrote:

        for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Selected == true)

        That's unnecessary, use listView1.Items.SelectedIndex. Then to apply the color change use listView1.Refresh();.

        My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

        1 Reply Last reply
        0
        • N Nagy Vilmos

          Learn to edit a post or learn what 'FOAD' stands for.


          Panic, Chaos, Destruction. My work here is done.

          A Offline
          A Offline
          al3xutzu00
          wrote on last edited by
          #4

          thanks man for the advice. I dont know what "FOAD" means but "FOAD" to you as well for helping me:D Regards, Alex

          “Be the change you want to see in the world.”

          1 Reply Last reply
          0
          • A al3xutzu00

            Hi, I have a list view with 5 columns and 4 items in that listView. When i click on a row ( item) of that listViewi want the whole row to be highlighted blue , and if i select another row, what that it to be selected as well. So basically i want it to look like the whole row is selected not just the first column item. here is what i tried : private void listView1_Click(object sender, EventArgs e) { for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Selected == true) { listView1.Items[i].BackColor = Color.Blue; } } } BUT this works after I change the selection of the row! for example i select row 1 , and when i select row 2 , then row 1 is highlited . Why guys? Any suggestions please? Regards, Alex

            “Be the change you want to see in the world.”

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            The SelectedIndexChanged event [^] looks more promising... :rolleyes:

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            R 1 Reply Last reply
            0
            • CPalliniC CPallini

              The SelectedIndexChanged event [^] looks more promising... :rolleyes:

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              You frakkin' cheater. You're referring to the documentation! :omg: :wtf:

              It is a crappy thing, but it's life -^ Carlo Pallini

              N 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                You frakkin' cheater. You're referring to the documentation! :omg: :wtf:

                It is a crappy thing, but it's life -^ Carlo Pallini

                N Offline
                N Offline
                Nagy Vilmos
                wrote on last edited by
                #7

                What? There's documentation! I thought he'd used a deccompiler thingy.


                Panic, Chaos, Destruction. My work here is done.

                R 1 Reply Last reply
                0
                • A al3xutzu00

                  Hi, I have a list view with 5 columns and 4 items in that listView. When i click on a row ( item) of that listViewi want the whole row to be highlighted blue , and if i select another row, what that it to be selected as well. So basically i want it to look like the whole row is selected not just the first column item. here is what i tried : private void listView1_Click(object sender, EventArgs e) { for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Selected == true) { listView1.Items[i].BackColor = Color.Blue; } } } BUT this works after I change the selection of the row! for example i select row 1 , and when i select row 2 , then row 1 is highlited . Why guys? Any suggestions please? Regards, Alex

                  “Be the change you want to see in the world.”

                  D Offline
                  D Offline
                  Dan Neely
                  wrote on last edited by
                  #8

                  Is there a reason that ListView.FullRowSelect[^] can't be used?

                  It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains. -- Pride and Prejudice and Zombies

                  A 1 Reply Last reply
                  0
                  • N Nagy Vilmos

                    What? There's documentation! I thought he'd used a deccompiler thingy.


                    Panic, Chaos, Destruction. My work here is done.

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #9

                    williamnw wrote:

                    What? There's documentation!

                    Yes, but it's usually top secret and can be reached only by elusive things like a Google search. :suss:

                    It is a crappy thing, but it's life -^ Carlo Pallini

                    N 1 Reply Last reply
                    0
                    • R Rajesh R Subramanian

                      williamnw wrote:

                      What? There's documentation!

                      Yes, but it's usually top secret and can be reached only by elusive things like a Google search. :suss:

                      It is a crappy thing, but it's life -^ Carlo Pallini

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #10

                      Wow! Does everyone else know about this?


                      Panic, Chaos, Destruction. My work here is done.

                      1 Reply Last reply
                      0
                      • D Dan Neely

                        Is there a reason that ListView.FullRowSelect[^] can't be used?

                        It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains. -- Pride and Prejudice and Zombies

                        A Offline
                        A Offline
                        al3xutzu00
                        wrote on last edited by
                        #11

                        Thanks a lot Dan. This worked perfectly. Alex :)

                        “Be the change you want to see in the world.”

                        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