?
Solved

Highlight list box when not focused in Delphi

Posted on 2009-04-14
1
Medium Priority
?
600 Views
Last Modified: 2013-11-23
In my Delphi 7 app I have a listbox and buttons to enable the user to move items up or down in the listbox. However, as soon as either button is clicked the highlight in the list box disappears. I would like to keep the highlight and have tried using SendMessge with the LB_SETCARETINDEX message but this does not work. The code is below and I would like to know how to get this to work.

procedure TfrmMain.cmdMoveUpClick(Sender: TObject);
var CurrIndex: integer;
begin
  with lstSelectedImages do
    if ItemIndex > 0 then begin
      CurrIndex:=ItemIndex;
      Items.Move(ItemIndex, (CurrIndex - 1));
      ItemIndex:=CurrIndex-1;
      SendMessage(lstSelectedImages.Handle, LB_SETCARETINDEX, ItemIndex, 0);
    end;
end;

Open in new window

0
Comment
Question by:galcott1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
SteveBay earned 2000 total points
ID: 24144183
Try this. It works well for me.
procedure TForm1.btnMoveUpClick(Sender: TObject);
var Index : Integer;
begin
     if lst1.ItemIndex > 1 then
          begin
          Index := lst1.ItemIndex  -1;
          lst1.Items.Move(lst1.ItemIndex, Index);
          lst1.ItemIndex := Index;
          lst1.Selected[Index] := True;
          lst1.SetFocus
          end;
 
end;
 
procedure TForm1.btnMoveDnClick(Sender: TObject);
var Index : Integer;
begin
     if (lst1.ItemIndex > 0) and (lst1.ItemIndex < lst1.Items.Count -1) then
          begin
          Index := lst1.ItemIndex  +1;
          lst1.Items.Move(lst1.ItemIndex, Index);
          lst1.ItemIndex := Index;
          lst1.Selected[Index] := True;
          lst1.SetFocus
          end;
end;

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question