Board index » delphi » TListBox "Selected" Property Failure

TListBox "Selected" Property Failure

I have a multiselect ownerdraw TListBox in my application. It's paired
with a component I downloaded which facilitates OLE drag-and-drop of
file names.

This component operates thus: it calls an event handler when it detects
the user has started a drag on the component it's paired with. This
event handler calls the component's Execute method to invoke OLE. When
execution returns to the event handler, the drag and drop is completed.

In my event handler, I load the file names corresponding to selected
items in the TListBox to a list maintained by the component.

Now the problem: when multiple items in the TListBox are selected by
holding down Shift and clicking, Windows shows only the first item
selected IS selected; the "selected" property returns false for all
other items, including selected ones. I've tried the Windows LB_GETSEL
message instead of the "selected" property and get the same outcome, so
I can see it's Windows and not Delphi. The items being missed are
colored in the manner of selected items.

Then I execute the component's Execute method, which permits dropping
of the single file name. Upon return, the "selected" property performs
as it should.

If I select multiple items with Ctrl instead of Shift, this problem
does not arise.

Does anybody have a clue? Source code for the component and my routine
will be furnished to anyone who thinks it'll help.
--
Thanks,
Elliott

"I don't want to achieve immortality through my
work. I want to achieve it by not dying." --

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 

Re:TListBox "Selected" Property Failure


In article <7ks5qp$pe...@nnrp1.deja.com>,
  Elliott <shev...@aol.com> wrote:

Quote
> Now the problem: when multiple items in the TListBox are selected by
> holding down Shift and clicking, Windows shows only the first item
> selected IS selected; the "selected" property returns false for all
> other items, including selected ones. I've tried the Windows LB_GETSEL
> message instead of the "selected" property and get the same outcome,
so
> I can see it's Windows and not Delphi. The items being missed are
> colored in the manner of selected items.

Here's how I solved my problem. It's a kludge, but it does the job:
=========================================================

   // Find the first selected item.
   if (shift key pressed) then
      with ListBox do begin
           for i := 0 to items.count - 1 do
               if selected[i] then begin
                   if i < ItemIndex
                      then begin
                             SelStart := i;
                             SelEnd   := ItemIndex;
                      end
                      else begin
                             SelStart := ItemIndex;
                             SelEnd   := i;
                      end;
                      break;
               end;
           for i := SelStart to SelEnd do
              Selected[i] := true;
      end;
=========================================================
--
Elliott

"I don't want to achieve immortality through my
work. I want to achieve it by not dying." --

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Other Threads