Why does sorting CheckBoxes in a ListBox not work?

I know you can use the CompareRows event to implement a custom sort, and there is an example, but why are “SortNumerical” and CheckBox sorting not build into the ListBox already? Is there a good reason? It seems wasted effort to have pretty much everyone implement it in the CompareRows event …

It seems wasted effort to have pretty much everyone implement it in the CompareRows event …

You are right. This is the same as people who create new ToolBar, FTC, etc. Class (and sold them) to have more functionalities than what found in native Class…

Also, remember the old REALbasic times; most of the times new features were half implemented and stay like that for many moons 'till they fill some holes (not all)… (RTF is a valid example: far less than the necessary minimum). :frowning:

Part of my rationale for writing apps is that one hour of programming might save 10 or 100 or 1000 hours of tedious work. If it doesn’t then why do it?

People click on the header and expect the rows to be sorted. If you can set a column to be of type CheckBox then you’d also expect it to follow that behaviour - after all it is not hard to implement. So why is it not build into the ListBox? Instead of one programmer at Xojo implementing it, now tens of thousands had/have to implement it themselves wasting much more time, plus all the time wasted by the people looking for how to do it or answering questions.

THAT is what doesn’t make sense to me.

How would you sort checkboxes ? By state checked, indeterminate and unchecked ? Or by label ?

At any rate, you could implement that with a hidden column that you fill with states or label, and sort from it.

Whatever you want to sort (Checkbox States) or Date Values (Totalseconds) or anything else you are free to put the numerical value in the CellTag. After that place this in your CompareRows Event of Listbox:

// I Assume that your Item is located in Column 1
if column = 1 then
    If Val(Me.CellTag(row1,column)) > Val(Me.CellTag(row2,column)) then
      result = 1
    else
      result = -1
    End if
    Return True
  else
   Return false
  end if

[quote=62812:@Michel Bujardet]How would you sort checkboxes ? By state checked, indeterminate and unchecked ? Or by label ?

At any rate, you could implement that with a hidden column that you fill with states or label, and sort from it.[/quote]

The checkbox column doesn’t have a label.

As for how to do the sorting: don’t use a hidden column, use the CompareRows event. Have a look at the example at http://documentation.xojo.com/index.php/ListBox.CompareRows

I really think this solution is hidden in a place where few beginners will find it, and a note in the main ListBox entry is required (can’t currently edit the documentation, otherwise I would have fixed that).

You don’t need to involve the CellTag for sorting a column with type CheckBox.

But this exactly illustrates my point. Everyone comes up with his or her own solution. A waste of time.

Well I wouldn’t blame this on Xojo. They give me the freedom to put it in Cell Tag, but I could use Rowtag also.
Otherwise if they would hardcode anything someone else would complain why he/she is limited.

Implementing compare rows is really trivial (often less than 3 lines of code) and there are really too many different situations to build something in (besides say declaring column numeric) …

Checkmarks are not in their own cell which would also make it hard to know what type of overall sort for the column you would want.

[quote=62822:@Markus Winter]Everyone comes up with his or her own solution. A waste of time.

[/quote]

Programming pleasure and creativity is all about finding one’s solution and workarounds. Don’t dismiss human brain as a waste of time, please…

I don’t think he means that at all. I think he considers a feature like this to be as basic and trivial as something like checking “Columns resizable” in the listbox properties. He is then free to go on and spend his brain power creating solutions and workarounds for things he deems to be more important.

In my opinion Xojo is more about ease of use, productivity and practicality rather than creating unique and brilliant solutions. He just wants the convenience of this one small thing already precoded for him - and why not? So much else is. With Xojo you really want an abundance of little things to be precoded for you. We aren’t using C or C++ where we have to make every little detail ourselves - that defeats the purpose of using Xojo (in my mind, at least).

As for how you’d sort checkboxes it’d be based upon what’s checked and what isn’t, I’d imagine.

[quote=63033:@Joshua Woods]
As for how you’d sort checkboxes it’d be based upon what’s checked and what isn’t, I’d imagine.[/quote]

Except that you often have text in the cell too and that could be text or a number…, and sometimes you would want to sort by checked and then text or number and sometimes ignore the check box in sorting or go by text.number Then checked…

They way it is now is most flexible. And implementing CompareRow really is trivial