- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am looking for a way to select(with highlighting) items in a ListBox from within the program. I already find those selected by the user, but would like to preset some items. I have not been able to find this in any of the on line or printed documentation or books that I have. Any body know how to do this?
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is some code to set the highlighted item in a listbox:
Code:
IF (SendControlMessage (hwnd, & ! parent window controlId, & ! listbox control id LB_SETCURSEL,& ! message token idx, & ! 0-based item index 0) == LB_ERR ) THEN ! deal with error END IF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm sorry. Should have been more explicit - I'm tying to do it using QuickWin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, DFLOGM -- it's independent on QuickWin.
The method is not quite intuitive: value argument should hold the index of the item to be selected, while index argument should contain the ordinal of selection:
will select 4th, 8th and 11th item (provided the listbox has "Multiple selection" style -- otherwise, you can select only one item). Retrieval of selected items is similar; the value will contain zero when there's no more selected items.
XFLOGM2, which is part of XFT library supports an array-based approach, where value can be an integer array.
Jugoslav
The method is not quite intuitive: value argument should hold the index of the item to be selected, while index argument should contain the ordinal of selection:
ret = DlgSet(Dlg, IDC_LIST1, 4, 1)
ret = DlgSet(Dlg, IDC_LIST1, 8, 2)
ret = DlgSet(Dlg, IDC_LIST1, 11, 3)
will select 4th, 8th and 11th item (provided the listbox has "Multiple selection" style -- otherwise, you can select only one item). Retrieval of selected items is similar; the value will contain zero when there's no more selected items.
XFLOGM2, which is part of XFT library supports an array-based approach, where value can be an integer array.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could also use DLGSENDCTRLMESSAGE(dlg, controlid, message, wparam, lparam). For this, you need to USE DFLOGM. I also see there is DLGSENDMESSAGE (Hwnd, message, wparam, lparam) in the same module.All list-box messages (integer*4) begin LB_ and details of them and the values needed for the parameters wparam, lparam (integer*4) can be found using the Help index, searching for "LB_".
You can also use the Windows API function SendMessage (interface found in module USER32, so you would need to add USE USER32 to your calling program). Here is an example using Sendmessage to an edit box to select all the text and replace it with a null-terminated text string stored in CHARTOTAL. SendMessage (and DlgSendMessage) needs the window handle for the
listbox and GetDlgItem is used for this.
listbox and GetDlgItem is used for this.
Code:
USE DFWIN ! This contains USE USER32, among other modules... USE DFWINTY ! This contains definitions of all the Integer parameters such as LB_SETSEL, LB_GETSEL, EM_GETSEL etc. type (dialog) dlg integer hweb CHARACTER*4 CHARTOTAL include 'resource.fd' ! generated by resource compiler, should contain definitions of all the dialog control ID's, like IDC_TOTALNUMBER etc. ..... ..... hweb = GetDlgItem (dlg%hwnd, IDC_TOTALNUMBER) iret = SendMessage (hweb, EM_SETSEL, 0, -1 ) iret = SendMessage (hweb, EM_REPLACESEL, 0, LOC(CHARTOTAL) )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the input. I was able to use the DLGSENDCTRLMESSAGE function in a callback routine to do what I need to do. I was not able to get the DlgSet version to work with my situation. Perhaps it is because of the MODAL dialog I am using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am guilty of not being precise again! I was able to get the DlgSet method to select list items but could not deselect in a controllable manner using that method. For that I used the DLGSENDCTRLMESSAGE technique.
Again, thanks for the input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just as a P.S., Sendmessage and DlgSendCtrlMessage and the like wait until the message has been processed by the window to which the message is sent before returning. If you want to send messages to controls and continue processing without waiting for the message to be processed, use PostMessage. I have found Sendmessage and Postmessage to work OK from within callbacks, as the dialog item appears to be updated quicker than using DlgSet in many cases.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page