Re: CListBox GetSelItems problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Define "incorrect result". I've never seen any problem with multiple-select listboxes.

Suppose your selection is items 4,5,6,7,8,9, a single contiguous block. Then GetSelCount
will return the value 6. I you deselect an item so your selection is 4,5,6,8,9, then
GetSelCount will return 5. What I do at that time is

int n = c_Whatever.GetSelCount();
CArray<int, int> sels;
sels.SetSize(n);
c_Whatever.GetSelItems(n, sels.GetData());

now I have an array of the elements. It would either be 6 items (4,5,6,7,8,9) or 5 items
(4,5,6,8,9). I've never seen this fail. I have major apps out there that have been
working for years that would have failed utterly if there were a bug like you describe.

What do you do with the selected items after you retrieve them? Be aware that if you do a
deletion, the world goes definitely weird; there are a couple different approaches to
handling deletion. But show us some code, including any insertions or deletions that
might be performed.
joe

On 20 Dec 2005 14:00:38 -0800, noureensyed@xxxxxxxxx wrote:

>Hi there,
>
>In an extended style CListBox, if I select multiple items and then
>deselect an item (that is not the last or first item), then GetSelItem
>returns the incorrect results.
>
>By deselecting an item that is not the first or last item in my
>selection, I get two non-continuous selections. Is that why I have
>incorrect results. Because the array that is returned by GetSelItem
>still contains the item number of the item that was deselected.
>
>The call to GetSelItem is on a certain button click. So I select all
>items, deselect some item from the middle of the selection, now click a
>button that needs to know the item numbers of the selected items. This
>is where I get an error because I shouldn't be getting the item number
>of the deselected item, but I do, and then I miss the last item in my
>selection, as the count of items to get I send into GetSelItem actually
>reflects the number of items selected.
>
>So if the list had 10 items, I deleselect one from the middle, my
>selection is composed of 9 items. I get nine items back, but that
>includes what was deselected, and so now I miss the last item that was
>actually selected.
>
>Any ideas on how to deal with this? Is GetSelItems not the method to be
>using here when my deselection is such that I end up with two
>non-continuous selections?
>
>Thank you.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: CListBox GetSelItems problem
    ... > deselect an item, ... > selection, I get two non-continuous selections. ... Because the array that is returned by GetSelItem ...
    (microsoft.public.vc.mfc)
  • CListBox GetSelItems problem
    ... deselect an item, ... selection, I get two non-continuous selections. ... Because the array that is returned by GetSelItem ...
    (microsoft.public.vc.mfc)
  • Re: unselecting
    ... "I've read tutorials, researched the help index, ... > entailed only clicking Deselect on that menu. ... discovering that making a selection anywhere else without ... OK, read the Help file. ...
    (alt.graphics.photoshop)
  • Re: unselecting
    ... "I've read tutorials, researched the help index, ... entailed only clicking Deselect on that menu. ... discovering that making a selection anywhere else without ... OK, read the Help file. ...
    (alt.graphics.photoshop)
  • Re: ActiveChart.Deselect wont Deselect
    ... XL is 'reluctant' to deselect something the user has just selected? ... activesheet and an activechart. ... However, selection is nothing! ... > Dim ElementID As Long, Arg1 As Long, Arg2 As Long ...
    (microsoft.public.excel.charting)