Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28435 Discussions

Hi-light items in list box selected in previous call

Neels
New Contributor II
444 Views
How do I highlight items that was selected in a list box on previous calls to the list box?

Neels
0 Kudos
8 Replies
anthonyrichards
New Contributor III
444 Views
I am not sure if it is possible, but you could try sending LB_SELITEMRANGE message with the fselect argument set to .TRUE. and the selection argument set to MAKELPARM(itemno,itemno) for each itemno in the list that you select?

iret=SendDlgItemMessage(hDlg,IDC_LISTBOX,LB_SELITEMRANGE, .TRUE.,MAKELPARAM(itemno,itemno) )

I'm not sure if an item will remain highlighted when you move on to the next item.
0 Kudos
Neels
New Contributor II
444 Views
Thanks Anthony,

I could not get it to work - maybe my own stupidity. I also tried the following without success:

bret = DlgSet(dlg, IDC_LIST_Plot_Select, i, DLG_SELCHANGE)

0 Kudos
Jugoslav_Dujic
Valued Contributor II
444 Views
Quoting neels
How do I highlight items that was selected in a list box on previous calls to the list box?

Not sure that I follow: what do you mean by "previous calls"? Is it a multi-selection list box (you got a singular/plural mismatch -- "items that was" -- in your original message so I'm not sure)?

A list box keeps its selection as long as the dialog box is alive. If you want to persist the selection between different invocations of the dialog box, and it is a multi-selection list, you have to store it in a SAVEd (or MODULE) variable.

To retrieve a multi-selection from a list box, use the following code structure (well, if I recall correctly, haven't used the feature for ages):

[fortran]integer, allocatable, save:: selection(:)
integer, save::              numSelected=0
logical::                    ret

!Setting the selection
do i = 1,numSelected
  ret = DlgSet(dlg, IDC_LISTBOX, selection(i), i)
end do

ret = DlgModal(...)

!Retrieving the selection
if (.not.allocated(selection)) allocate(selection(numItems))
numSelected = 0
selection = 0
do while(DlgGet(dlg, IDC_LISTBOX, selection(numSelected+1), numSelected+1))
  numSelected = numSelected+1
end do
[/fortran]

Hope this helps,
0 Kudos
Neels
New Contributor II
444 Views
Jugoslav

I have the code as you suggested. It works fine to do a multiple selection from the list box. If I close the list box (and in this case) plot the selected curves, it works. If I open the list box again, I can select more items and then they, as well as the previously selected items are now plotted. What I need is on the second (and subsequent) visits to the list box for the selected items in the list box to be highlighted so I can unselect some of them and add others. To select and unselect them I can do the code, but to highlight the previously selected ones on the second or more visits is what I have trouble with.

Thanks
Neels
0 Kudos
Jugoslav_Dujic
Valued Contributor II
444 Views
Um, still not sure that I follow when your "I" means "Neels the programmer" and when "Neels the user" :D. I don't think that a list item can be three-state ("selected", "highhighted" and "none").

What you describe vaguely resembles the UI pattern where you have two distinct "Available" and "Selected" lists, and have two buttons to move from one to another, like in the picture below. In the left list, you would maintain "Available" curves, and in the right, the "Selected" curves, which you will have to persist between calls; no item may be in both lists simultaneiously. Am I on the right track?





0 Kudos
Neels
New Contributor II
444 Views
The first time I open the list box it looks as follows:


I then select some items to plot:


And then I plot them.

Now I want to add more items to plot and remove some previously selected but when I open the list box again, it looks like the first time, not as it was after I selected the items to plot. I want it to now look as it does in the second figure above.

It is straight forward to do the book keeping to know which items selected on previuos calls to highlight on the subsequent calls to the list box, I just cannot get them highlighted. Myquestion is: How do I do it?

Hope this explains better.
Neels
0 Kudos
Jugoslav_Dujic
Valued Contributor II
444 Views
I apologize in advance for being dense; have in mind that I'm a Bosnian after all :).

I believe I answered that question above, in my first post; did you perhaps skim it too quickly? According to the documentation (haven't tried it for a long time, please verify), the following code:

do i=1,3
ret = DlgSet(dlg, IDC_LISTBOX, i*2, i)
end do

will select the 2nd, 4th and 6th item in a multi-selection list box. If you replace the "i*2" with A(i), where A is an array of indices, it will select items with indices A(1), A(2) and A(3). You get the contents of A from the previous invocation of the dialog box, as I outlined in my previous post.

Now, you would have a problem if in the meanwhile you remove or add some items at the beginning of the list, i.e. if the "PITrace(1)" was the 2nd item in first call, but will become 1st in the second call. If that's your situation, tough luck, you will have to do some string matching (i.e. instead of array of indices use an array of strings), but you didn't indicate so far that would be the case.
0 Kudos
Neels
New Contributor II
444 Views
Thanks Jogoslav

Yes, you did answer my question in your first post, I just did not realize it- seeing that neither our mother tongues is English!

I have it working now.

Neels
0 Kudos
Reply