Hi,
I've been away from programming (again) for awhile, and I'm trying to revive a project I started last year.
I have a listbox that gets created on the Form with LBS_SORT not checked. Later, I add unsorted data.
The user may want to sort the items, so I provide a command button that clears the listbox, (attempts to) set the listbox to enable sorting, then reloads the data:
FF_ListBox_ResetContent HWND_STEAMWHEELLIST_LBLOCOINFOLIST 'clear unsorted items
SendMessage HWND_STEAMWHEELLIST_LBLOCOINFOLIST, %LBS_Sort, 0, 0 'set status to Sort
Call PrepList (%TRUE) 'add the items again
Seems to me that SendMessage is not enabling the LB to sort the items when re-added...
I know I'm wrong about something I'm assuming - I just can't see it.
Can anyone clue me in?
Thanks,
-John
LBS_SORT is not a message, but a window style. The technique to change dynamically the style is:
' Switch it off
dwStyle = GetWindowLong(HWND_STEAMWHEELLIST_LBLOCOINFOLIST, %GWL_STYLE)
dwStyle = (dwStyle AND NOT %LBS_SORT)
CALL SetWindowLong(HWND_STEAMWHEELLIST_LBLOCOINFOLIST, %GWL_STYLE, dwStyle)
...
' Switch it on
dwStyle = GetWindowLong(HWND_STEAMWHEELLIST_LBLOCOINFOLIST, %GWL_STYLE)
dwStyle = (dwStyle OR %LBS_SORT)
CALL SetWindowLong(HWND_STEAMWHEELLIST_LBLOCOINFOLIST, %GWL_STYLE, dwStyle)
But it doesn't work with list boxes, so you need to kill and recreate it with the LBS_SORT style.
(Thanks Jose)
.... or, you could create two ListBoxes on the Form; one with the sort style set and the other without. You could then show/hide the applicable ListBox as necessary. This is a bit of a hack but it is simple to use and easy to understand and implement.
Jose and Paul,
Hmmm, I see I have some re-writing to do...
For my own learning, I'm going to try both ideas and see which works best for me.
Thanks for the help!
-John