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. Question about ListView

Question about ListView

Scheduled Pinned Locked Moved C#
question
4 Posts 2 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.
  • T Offline
    T Offline
    Teuz
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • T Teuz

      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

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      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 check e.Item.Selected to see if the item being drawn is selected and if it needs a focus rectangle drawing or not.

      Simon

      T 1 Reply Last reply
      0
      • S Simon P Stevens

        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 check e.Item.Selected to see if the item being drawn is selected and if it needs a focus rectangle drawing or not.

        Simon

        T Offline
        T Offline
        Teuz
        wrote on last edited by
        #3

        I'm trying that now, thanks alot for your quick answer.

        S 1 Reply Last reply
        0
        • T Teuz

          I'm trying that now, thanks alot for your quick answer.

          S Offline
          S Offline
          Simon P Stevens
          wrote on last edited by
          #4

          No problem.

          Simon

          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