AdvPolyList and Enter key

Hi

I would like to build main menu with AdvPoly components.

AdvPolyList_Main
AdvPolyList_Sub

procedure TForm1.AdvPolyList_MainClick(Sender: TObject);
begin
  AdvPolyList_Sub.SetFocus;
  AdvPolyList_Sub.SelectItem(0);
end;

procedure TForm1.AdvPolyList_MainKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=VK_RETURN then
  begin
    AdvPolyList_Sub.SetFocus;
    AdvPolyList_Sub.SelectItem(0);
  end;
end;

If I click a ImageTextItem of AdvPolyList_Main, the sub get focus and select first item perfect.

Problems:
1, If I push the Enter key, on AdvPolyList_Main, the click event didnt fired.
2, If I push the Enter key, on AdvPolyList_Main, the keydown event fired, and the AdvPolyList_Sub's first item flashed, but after unselected.
3, The extra question: how I set off the Enter key's effect: the item will be unselect state.
 
How to reproduce: put 2 components to a form and set the events.

Delphi XE, Windows 7, TMS CP 7.1.6.0

Thanks in advance.


Hi, 


Can you try to move the key code to the KeyUp instead. Changing the focus between 2 controls in a KeyDown / KeyUp event routine might have unexpected results.

Kind Regards, 
Pieter

Thanks, in the KeyUp do it.  I memorize the KeyDown-focus changing case.

I found the problem 1 solution, on Enter key not the AdPolyList.OnClick start, but AdPolyList.Item.Onclick start. OK.

Problem 3: how can I set off the Enter key's effect: the item will be unselect state (like a downed button).

You need to set the Selectable property for each item to false


Kind Regards, 
Pieter

I use keyboard for menu. If Selectable=false, then this item not usable for keyboard.

If
I press Enter on item, its lost the "selected" color. Default the
selected item is yellow, but after Enter the yellow gone, stay white.
I would like stay yellow.

Sorry, this is currently not possible. 

The possible solution: use a global marker variable, for example LastKeyIsEnter.

In AdvPolyList_Main.OnkeyDown set
if key=VK_RETURN then
  begin
    LastKeyIsEnter:=true;
  end

In AdvPolyList_Main.OnItemDeSelect set
  if LastKeyIsEnter then
  begin
    allow:=false;
    LastKeyIsEnter:=false;
  end;

In this way visible the selected mainmenu item, when the submenu show.

Thanks all.