C. Griffin
C. Griffin

Reputation: 681

Dynamics AX 2009: How to sort an unbound form control's contents?

I was using a Listbox control on a form, and programmatically adding items to it. I thought that if I called the sort(SortOrder::Ascending) method on the Listbox it would do just that -- however, I was wrong.

Ultimately, I am unable to achieve these results. I don't have to use a Listbox, but I need two pieces of functionality:

  1. Programmatically be able to add Strings to the control
  2. Be able to run code when an item is clicked or selected
  3. The list should be able to be sorted alphabetically

Upvotes: 1

Views: 1710

Answers (1)

Alex Kwitny
Alex Kwitny

Reputation: 11544

I couldn't get the listbox to sort either. Easiest might be to use a "ListView" control instead of a listbox. You can see how to use AND sort in (AOT>Forms\tutorial_Form_ListControl). Your requirements #1 & #2 are possible on almost anything you do. The issue is sorting I'd think.

Another option, keep a local variable that controls the sorting. I would use a collection class, either an Array or Map so you can control the sorting via key-value, then you could just re-load the listbox when the user added/removed something. Since it's client side and it doesn't sound like the listbox will have 1000+ controls, re-loading it probably won't be a significant performance hit. You can also use listbox.insert([value], [index]), to insert into the correct location if you are controlling properly.

Another option, hi-jack any simple table from the AOT (TmpABC is a good one), insert the values, then sort using a simple query or even better, set the TmpABC to the ListView control's datasource and just sort via datasource sort..

Upvotes: 3

Related Questions