Listbox, prevent sorting

  1. 2 years ago

    Christoph D

    10 Feb 2018 Pre-Release Testers, Xojo Pro

    Dumb question: how to avoid sorting a listbox when the user clicks on the headers?

    BTW I can of course reload the listbox when the user clicks on the header, (I would call this a workaround. But surely there should be a better way.

    Return True in the .SortColumn Event ?

    http://docs.xojo.com/index.php/ListBox.SortColumn

  2. Emile S

    10 Feb 2018 Answer Europe (France, Strasbourg)

    Return True in the .SortColumn Event ?

    http://docs.xojo.com/index.php/ListBox.SortColumn

  3. Christoph D

    10 Feb 2018 Pre-Release Testers, Xojo Pro
    Edited 2 years ago

    I'm getting old ... :)

    But it still shows the ^ icons in the header when pressed. Any way to disable this too?

  4. Emile S

    10 Feb 2018 Europe (France, Strasbourg)

    Yes, there is. Where , How ?

    I put that in a MenuEvent to remove the small Sort icon. Thanks to the Xojo Engineer tip.

    LB.SortedColumn = -1
    LB.HasHeading = False
    LB.HasHeading = True

  5. Alain C

    10 Feb 2018 Pre-Release Testers, Xojo Pro Switzerland

    The simplest way is to prevent the action from being called.

    me.HeaderType(0)=Listbox.HeaderTypes.NotSortable

    http://docs.xojo.com/index.php/ListBox.HeaderType

  6. Emile S

    10 Feb 2018 Europe (France, Strasbourg)

    I forgot that one…

  7. 6 weeks ago

    Frank K

    Oct 5 Pre-Release Testers, Xojo Pro Germany

    This question occurred to me when I wanted to do a "Select all" by pressing the header column 4. I managed this with a computed property:

    Private isExportAll As Boolean
    Get
       Return misExportAll
    End Get 
    
    Set
       misExportAll = value
       if value = true then 
          lbUebungen.SortedColumn = -1 
          lbUebungen.HasHeading = false 
          lbUebungen.HasHeading = true
          isExportAll = False
       end if 
    End Set
    
    End Property

    Then, in the event HeaderPressed:

    Function HeaderPressed(column as Integer) As Boolean 
    if column = 4 then
       if isExportAll then 
          return false
       end if
    
    // ... Do what you want to be accomplished
    
    // Sort-Indikator ausschalten
       isExportAll = true
    end if
    End Function
  8. Ivan T

    Oct 5 Pre-Release Testers

    @Christoph Dnbsp;Vocht I can of course reload the listbox when the user clicks on the header

    Just WHY?

    All the columns are sorted

  9. Emile S

    Oct 5 Europe (France, Strasbourg)

    Read there: ListBox.SortColumn to learn how to avoid Sorting a Column from a Listbox.

    There is no artwork to watch, but only a few lines to read. ;)

  10. Tim J

    Oct 5 Pre-Release Testers Dehydrating in AZ

    @Frank K This question occurred to me when I wanted to do a "Select all" by pressing the header column

    Quite an elegant solution. Thanks for sharing.

or Sign Up to reply!