ListView - Select ListViewItem
-
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.”
-
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.”
Learn to edit a post or learn what 'FOAD' stands for.
Panic, Chaos, Destruction. My work here is done.
-
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.”
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 uselistView1.Refresh();
.My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)
-
Learn to edit a post or learn what 'FOAD' stands for.
Panic, Chaos, Destruction. My work here is done.
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.”
-
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.”
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] -
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]You frakkin' cheater. You're referring to the documentation! :omg: :wtf:
It is a crappy thing, but it's life -^ Carlo Pallini
-
You frakkin' cheater. You're referring to the documentation! :omg: :wtf:
It is a crappy thing, but it's life -^ Carlo Pallini
What? There's documentation! I thought he'd used a deccompiler thingy.
Panic, Chaos, Destruction. My work here is done.
-
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.”
-
What? There's documentation! I thought he'd used a deccompiler thingy.
Panic, Chaos, Destruction. My work here is done.
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
-
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
Wow! Does everyone else know about this?
Panic, Chaos, Destruction. My work here is done.
-
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
Thanks a lot Dan. This worked perfectly. Alex :)
“Be the change you want to see in the world.”