- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a dialog box with two radio buttons and a list box.
If button one is selected the list box shows one lot of data, if button two is selected the list box shows another lot of data. In both cases the first item in the list box is selected using iret=SendMessage(hListBox,LB_SETCURSEL,0,0).
If I press the down arrow I expect the second item in the list to be selected but instead the other radio button is selected and the contents of the list box change (as the radio button had focus).
I thought I could set focus to the list box using iret=SetFocus(IDC_LISTBOX), but it doesn't work (it returns 0).
The only way I can get it to work is to pick the fist item in the list box with the cursor then press the down arrow.
Can you suggest how I can do this.
Thanks,
David
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
SetFocus sets the focus to a window designed by its handle. You must retrieve the window handle of the control using DlgGetItem function.
iret=SetFocus(DlgGetItem(hdlg,IDC_LISTBOX));
should work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get the index of the presently selected item by using
item=SendDlgItemMessage(dlg%hWnd,IDC_LISTBOX, LB_GETCURSEL, 0,0)
Then you can select the next item using
iret=SendDlgItemMessage(dlg%hWnd,IDC_LISTBOX, LB_SETCURSEL, MAKEWPARAM(item+1,0),0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I should have realised I'd forgoten the DlgGetItem()
David

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