Change (or disable) selection color of listview [SOLVED partially]
-
sodevrom wrote:
a)Keep selection visible (with blue color, not gray, this is the problem with HideSelection) always
That's by design; whatever is focused is drawn in the "selected" color. That way I can (as a user) visually differentiate between the ListView that's focused (and will react to keyboard-input) and which won't. If both were using blue, it would imply that both have the input-focus. That's not possible in Windows, since there can only be one active control with input-focus. There's no "neat" way to do this. Why no owner-drawing btw?
sodevrom wrote:
b)Remember selected objects, but do not show the selection at all (because if the selection is visible, than the custom back/fore color are not visible), so I can "mimic" the selection by setting a custom back/fore color to the items.
Remembering selected objects can be done by adding them to a generic list, whenever you select one. Sounds like you want to replace the default multiselect by your own version?
I are Troll :suss:
Hello, I know this is possible because I seen it in action somewhere. I do not want to use owner draw, because I would have to implement tons of things, and I still want the list to look exactly like in windows (with the theme from windows). Still waiting for some suggestions. Thanks!
-
Hello guys, First, I don't want to use OwnerDraw, that is a condition I have :( . What I want is set a custom color to the selection of a listview. I want the color to be visible even if the listview is not focused. I know about the HideSelection member, but that's not what I need. I tried to overrwrite the onselectionindexchanged, and make the item.selected=false, and after that, set a custom back/fore color. This does not work because I have multiple items, and it deselects all items but one. I need one of 2 things: a)Keep selection visible (with blue color, not gray, this is the problem with HideSelection) always b)Remember selected objects, but do not show the selection at all (because if the selection is visible, than the custom back/fore color are not visible), so I can "mimic" the selection by setting a custom back/fore color to the items. Now I have been spending over 4 hours now on this stupid issue, and no luck. Anyone has a suggestion? It would help a lot. *******************solution Instead of setting the color in the on selected changed event, we can do it on mouse up. It's not perfect, but it's the best I got. The best way to do this is using a custom draw listview. Here is the code:
List selections=new List();
protected override void OnMouseUp(MouseEventArgs e)
{
selections = this.SelectedIndices.Cast().ToList(); //store selection
this.SelectedIndices.Clear(); //clear selectionfor (int i = 0; i < this.Items.Count; i++) { if (this.selections.Contains(i)) this.Items\[i\].BackColor = Color.Blue; //if selected, make it blue else this.Items\[i\].BackColor = Color.White; //if not selected, make it white } base.OnMouseUp(e); }
modified on Monday, August 2, 2010 9:01 PM
I'm not sure I understand your question fully, but I think you can set the Enabled Property to true and the Readonly property to true also. Apologies in advance if I have misunderstood your question.
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners. -
Hello guys, First, I don't want to use OwnerDraw, that is a condition I have :( . What I want is set a custom color to the selection of a listview. I want the color to be visible even if the listview is not focused. I know about the HideSelection member, but that's not what I need. I tried to overrwrite the onselectionindexchanged, and make the item.selected=false, and after that, set a custom back/fore color. This does not work because I have multiple items, and it deselects all items but one. I need one of 2 things: a)Keep selection visible (with blue color, not gray, this is the problem with HideSelection) always b)Remember selected objects, but do not show the selection at all (because if the selection is visible, than the custom back/fore color are not visible), so I can "mimic" the selection by setting a custom back/fore color to the items. Now I have been spending over 4 hours now on this stupid issue, and no luck. Anyone has a suggestion? It would help a lot. *******************solution Instead of setting the color in the on selected changed event, we can do it on mouse up. It's not perfect, but it's the best I got. The best way to do this is using a custom draw listview. Here is the code:
List selections=new List();
protected override void OnMouseUp(MouseEventArgs e)
{
selections = this.SelectedIndices.Cast().ToList(); //store selection
this.SelectedIndices.Clear(); //clear selectionfor (int i = 0; i < this.Items.Count; i++) { if (this.selections.Contains(i)) this.Items\[i\].BackColor = Color.Blue; //if selected, make it blue else this.Items\[i\].BackColor = Color.White; //if not selected, make it white } base.OnMouseUp(e); }
modified on Monday, August 2, 2010 9:01 PM
Create your own list view and your own list view items. This is the easiest way to get the results you desire. In fact, it would have taken less than 4 hours, I bet.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost
-
Hello, I know this is possible because I seen it in action somewhere. I do not want to use owner draw, because I would have to implement tons of things, and I still want the list to look exactly like in windows (with the theme from windows). Still waiting for some suggestions. Thanks!
sodevrom wrote:
I know this is possible because I seen it in action somewhere
Yup, it's possible :)
sodevrom wrote:
I do not want to use owner draw, because I would have to implement tons of things
You want non-standard behavior, and that has to be implemented somewhere. Owner-drawing might sound like overkill, especially if you've been looking at examples that draw a lot manually. The example on MSDN[^] looks rather short and might do the trick.
sodevrom wrote:
and I still want the list to look exactly like in windows
Make sure you're using the SystemColors[^] when drawing.
I are Troll :suss:
-
Hello guys, First, I don't want to use OwnerDraw, that is a condition I have :( . What I want is set a custom color to the selection of a listview. I want the color to be visible even if the listview is not focused. I know about the HideSelection member, but that's not what I need. I tried to overrwrite the onselectionindexchanged, and make the item.selected=false, and after that, set a custom back/fore color. This does not work because I have multiple items, and it deselects all items but one. I need one of 2 things: a)Keep selection visible (with blue color, not gray, this is the problem with HideSelection) always b)Remember selected objects, but do not show the selection at all (because if the selection is visible, than the custom back/fore color are not visible), so I can "mimic" the selection by setting a custom back/fore color to the items. Now I have been spending over 4 hours now on this stupid issue, and no luck. Anyone has a suggestion? It would help a lot. *******************solution Instead of setting the color in the on selected changed event, we can do it on mouse up. It's not perfect, but it's the best I got. The best way to do this is using a custom draw listview. Here is the code:
List selections=new List();
protected override void OnMouseUp(MouseEventArgs e)
{
selections = this.SelectedIndices.Cast().ToList(); //store selection
this.SelectedIndices.Clear(); //clear selectionfor (int i = 0; i < this.Items.Count; i++) { if (this.selections.Contains(i)) this.Items\[i\].BackColor = Color.Blue; //if selected, make it blue else this.Items\[i\].BackColor = Color.White; //if not selected, make it white } base.OnMouseUp(e); }
modified on Monday, August 2, 2010 9:01 PM
This is a very basic solution, but here it is anyway:
private List selections = new List();
private bool dontChange = false;private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (!dontChange)
{
dontChange = !dontChange;
int selectedIndex = listView2.SelectedIndices[0];listView1.SelectedIndices.Clear(); //check if we're deselecting/selecting if (selections.Contains(selectedIndex)) { selections.Remove(selectedIndex); listView1.Items\[selectedIndex\].BackColor = Color.White; } else { selections.Add(selectedIndex); listView1.Items\[selectedIndex\].BackColor = Color.Blue; } } else { dontChange = !dontChange; }
}
of course this only works if you're selecting one item at a time. If you're doing an extended selection (meaning using Ctrl or Shift to select items) it wouldn't work because when you click the first time, it will add the item, then when you click the second time, it tries to make all of the items selected, which would deselect the first item. You'd have to include some key checking to see if Ctrl or Shift was down.
-
This is a very basic solution, but here it is anyway:
private List selections = new List();
private bool dontChange = false;private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (!dontChange)
{
dontChange = !dontChange;
int selectedIndex = listView2.SelectedIndices[0];listView1.SelectedIndices.Clear(); //check if we're deselecting/selecting if (selections.Contains(selectedIndex)) { selections.Remove(selectedIndex); listView1.Items\[selectedIndex\].BackColor = Color.White; } else { selections.Add(selectedIndex); listView1.Items\[selectedIndex\].BackColor = Color.Blue; } } else { dontChange = !dontChange; }
}
of course this only works if you're selecting one item at a time. If you're doing an extended selection (meaning using Ctrl or Shift to select items) it wouldn't work because when you click the first time, it will add the item, then when you click the second time, it tries to make all of the items selected, which would deselect the first item. You'd have to include some key checking to see if Ctrl or Shift was down.
Hello, I tried something like you said, before posting on this forum, but I don't think it's going to work. Now the problem is when selecting multiple items (by dragging). It can work only with 1 item, but if you have multiple items, and remove one item at a time from the SelectedIndices, it will call the event again and again. Don't know exactly how to explain. Thanks anyways
-
Create your own list view and your own list view items. This is the easiest way to get the results you desire. In fact, it would have taken less than 4 hours, I bet.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost
-
I'm not sure I understand your question fully, but I think you can set the Enabled Property to true and the Readonly property to true also. Apologies in advance if I have misunderstood your question.
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.Hi, I don't think you understand exactly what I want. I simply want to view the selection in blue always (with multiple items), even if the listview has no focus. In a normal case, when the listivew loses focus, the selection turns gray, and you can't see it good.
-
This is a very basic solution, but here it is anyway:
private List selections = new List();
private bool dontChange = false;private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (!dontChange)
{
dontChange = !dontChange;
int selectedIndex = listView2.SelectedIndices[0];listView1.SelectedIndices.Clear(); //check if we're deselecting/selecting if (selections.Contains(selectedIndex)) { selections.Remove(selectedIndex); listView1.Items\[selectedIndex\].BackColor = Color.White; } else { selections.Add(selectedIndex); listView1.Items\[selectedIndex\].BackColor = Color.Blue; } } else { dontChange = !dontChange; }
}
of course this only works if you're selecting one item at a time. If you're doing an extended selection (meaning using Ctrl or Shift to select items) it wouldn't work because when you click the first time, it will add the item, then when you click the second time, it tries to make all of the items selected, which would deselect the first item. You'd have to include some key checking to see if Ctrl or Shift was down.
-
Hello guys, First, I don't want to use OwnerDraw, that is a condition I have :( . What I want is set a custom color to the selection of a listview. I want the color to be visible even if the listview is not focused. I know about the HideSelection member, but that's not what I need. I tried to overrwrite the onselectionindexchanged, and make the item.selected=false, and after that, set a custom back/fore color. This does not work because I have multiple items, and it deselects all items but one. I need one of 2 things: a)Keep selection visible (with blue color, not gray, this is the problem with HideSelection) always b)Remember selected objects, but do not show the selection at all (because if the selection is visible, than the custom back/fore color are not visible), so I can "mimic" the selection by setting a custom back/fore color to the items. Now I have been spending over 4 hours now on this stupid issue, and no luck. Anyone has a suggestion? It would help a lot. *******************solution Instead of setting the color in the on selected changed event, we can do it on mouse up. It's not perfect, but it's the best I got. The best way to do this is using a custom draw listview. Here is the code:
List selections=new List();
protected override void OnMouseUp(MouseEventArgs e)
{
selections = this.SelectedIndices.Cast().ToList(); //store selection
this.SelectedIndices.Clear(); //clear selectionfor (int i = 0; i < this.Items.Count; i++) { if (this.selections.Contains(i)) this.Items\[i\].BackColor = Color.Blue; //if selected, make it blue else this.Items\[i\].BackColor = Color.White; //if not selected, make it white } base.OnMouseUp(e); }
modified on Monday, August 2, 2010 9:01 PM
You could write your own control? Create a user control and add a panel with with background and add labels one below the other, you can provide a property that allows to set the background of the labels. Add some internal logic to maintain selection, colors, text, indexes, etc... Should be less then 4 hours to get you going.
V.