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. Preventing the user to resize the ListView columns

Preventing the user to resize the ListView columns

Scheduled Pinned Locked Moved C#
6 Posts 4 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.
  • S Offline
    S Offline
    SimpleData
    wrote on last edited by
    #1

    Hi, I have a ListView in details view and I would like to prevent the user to resize the column widths. Thanks in advance.

    L 1 Reply Last reply
    0
    • S SimpleData

      Hi, I have a ListView in details view and I would like to prevent the user to resize the column widths. Thanks in advance.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      does it have a ColumnWidthChanging event? and would that support canceling? :)

      Luc Pattyn


      Local announcement (Antwerp region): Lange Wapper? Neen!


      S 1 Reply Last reply
      0
      • L Luc Pattyn

        does it have a ColumnWidthChanging event? and would that support canceling? :)

        Luc Pattyn


        Local announcement (Antwerp region): Lange Wapper? Neen!


        S Offline
        S Offline
        SimpleData
        wrote on last edited by
        #3

        Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.

        M D 2 Replies Last reply
        0
        • S SimpleData

          Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.

          M Offline
          M Offline
          Manas Bhardwaj
          wrote on last edited by
          #4

          SimpleData wrote:

          Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.

          You can use the ColumnWidthChanging [^]event of the listview. But surprisingly, it seems to have a bug which MS has accepted. You can have a look here[^]. A possible workaround would be to cancel the event, and set the old width again. (kinda dirty...)

          private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
          {
          e.NewWidth = this.listView1.Columns[e.ColumnIndex].Width;
          e.Cancel = true;
          }

          Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

          1 Reply Last reply
          0
          • S SimpleData

            Yes it has and supports canceling but user can change the width even it's canceled. Just the resizing animation isn't shown.

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            The trick is to also set the NewWidth property to the existing Width:

            private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
            {
            e.NewWidth = listView.Columns[e.ColumnIndex].Width;
            e.Cancel = true;
            }

            [Edit] Manas posted whilst I was posting! :laugh: [/Edit]

            Dave
            Generic BackgroundWorker - My latest article!
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Why are you using VB6? Do you hate yourself? (Christian Graus)

            S 1 Reply Last reply
            0
            • D DaveyM69

              The trick is to also set the NewWidth property to the existing Width:

              private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
              {
              e.NewWidth = listView.Columns[e.ColumnIndex].Width;
              e.Cancel = true;
              }

              [Edit] Manas posted whilst I was posting! :laugh: [/Edit]

              Dave
              Generic BackgroundWorker - My latest article!
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Why are you using VB6? Do you hate yourself? (Christian Graus)

              S Offline
              S Offline
              SimpleData
              wrote on last edited by
              #6

              Thank you all. Workaround works like a charm. :D

              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