Results 1 to 4 of 4

Thread: [RESOLVED] Why disabling DGV Column Sorting, disables DataGridViewAutoSizeColumn mode?

  1. #1

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    329

    Resolved [RESOLVED] Why disabling DGV Column Sorting, disables DataGridViewAutoSizeColumn mode?

    Hello!

    I have DGV perfectly fine, it is not bound to anything, populated programmatically, something like this:
    Name:  01.jpg
Views: 372
Size:  26.4 KB

    Then I needed to disable Column Sorting when I click on any column header, so I inserted this code:
    VB.NET Code:
    1. For Each dgvc As DataGridViewColumn In DataGridView1.Columns
    2.             dgvc.SortMode = DataGridViewColumnSortMode.NotSortable
    3.         Next

    Then all the columns in my DGV are not in Autosize mode anymore:
    Name:  02.jpg
Views: 334
Size:  26.5 KB

    The column sorting functionality is working fine now, but my Columns are not in Autosize mode anymore.

    Is it possible to have both functionalities working?
    Last edited by Spybot; Oct 13th, 2020 at 08:17 PM.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Why disabling DGV Column Sorting, disables DataGridViewAutoSizeColumn mode?

    I see nothing in that screenshot that indicates that the columns aren't auto-sizing anymore.

    Now, you might say, "But in the second screenshot, the columns are clearly narrower than in the first screenshot!!!"

    To which I would say, yes, but what is probably happening is that, since the columns can no longer be sorted, the "extra width" from the first screenshot that was set aside in each column header to display the little arrow that indicates the column and direction of sorting isn't needed any longer, so each column is "shrunk" by that size.

  3. #3

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    329

    Re: Why disabling DGV Column Sorting, disables DataGridViewAutoSizeColumn mode?

    OK, so The Autosizemode is still working, it's just that all the columns were shrunk that little arrow on the column headers.
    So I guess I'll need to make the column Headers unclickable instead of not sortable.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Why disabling DGV Column Sorting, disables DataGridViewAutoSizeColumn mode?

    I think that using Programmatic instead of NotSortable should work. That still leaves space for a sorting glyph but, unless you provide code to do so, will not actually do any sorting or display a glyph.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width