Question about ListView
-
Hi guys, This is a quick question: I was wondering if it's possible to remove that dotted border on a listview selected item, anyone knows how? Sorry if I missed some simple thing :P
You can modify the list view by making is partially owner drawn. You set the
OwnerDraw
property on the list view to true, then handle the various Draw events.listView1.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(listView1\_DrawColumnHeader); listView1.DrawItem += new DrawListViewItemEventHandler(listView1\_DrawItem); listView1.DrawSubItem += new DrawListViewSubItemEventHandler(listView1\_DrawSubItem); // Draw sub item event handler void listView1\_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawDefault = true; } // Draw item event handler void listView1\_DrawItem(object sender, DrawListViewItemEventArgs e) { /\* PUT YOUR CODE HERE \*/ //e.Graphics...Draw stuff //e.Graphics...Draw stuff e.DrawDefault = true; } // Draw header event handler void listView1\_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawDefault = true; }
The events are triggered each time that part of the list view needs redrawing, and you just draw what ever you want onto the graphics object provided. You can call handy methods on the event args object like
DrawText()
to do the text drawing for you. Then all you do is leave out the focus rectangle, and if required, draw your own focus rectangle in the style you want. You will need to checke.Item.Selected
to see if the item being drawn is selected and if it needs a focus rectangle drawing or not.Simon
-
You can modify the list view by making is partially owner drawn. You set the
OwnerDraw
property on the list view to true, then handle the various Draw events.listView1.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(listView1\_DrawColumnHeader); listView1.DrawItem += new DrawListViewItemEventHandler(listView1\_DrawItem); listView1.DrawSubItem += new DrawListViewSubItemEventHandler(listView1\_DrawSubItem); // Draw sub item event handler void listView1\_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawDefault = true; } // Draw item event handler void listView1\_DrawItem(object sender, DrawListViewItemEventArgs e) { /\* PUT YOUR CODE HERE \*/ //e.Graphics...Draw stuff //e.Graphics...Draw stuff e.DrawDefault = true; } // Draw header event handler void listView1\_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawDefault = true; }
The events are triggered each time that part of the list view needs redrawing, and you just draw what ever you want onto the graphics object provided. You can call handy methods on the event args object like
DrawText()
to do the text drawing for you. Then all you do is leave out the focus rectangle, and if required, draw your own focus rectangle in the style you want. You will need to checke.Item.Selected
to see if the item being drawn is selected and if it needs a focus rectangle drawing or not.Simon
-
No problem.
Simon