Hi.

If I define a lookup field, there will be a corresponding pick-list in the dbgrid. Is there a way to open this pick-list with the keyboard, instead of clicking on it? Otherwise I may have to use a TDBlookupcombobox in every column with a pick-list, because the user may not have a mouse.

TIA,

Eduardo

I know Alt-DownArrow opens the pick-list, but only after the user at least presses another key. I'd like to show the drop down button as soon as the cell is entered.

Hi.

If I define a lookup field, there will be a corresponding pick-list in the dbgrid. Is there a way to open this pick-list with the keyboard, instead of clicking on it? Otherwise I may have to use a TDBlookupcombobox in every column with a pick-list, because the user may not have a mouse.

TIA,

Eduardo

I know Alt-DownArrow opens the pick-list, but only after the user at least presses another key. I'd like to show the drop down button as soon as the cell is entered.

Hi ecostas, try this my function that simules keyboard pressed:

procedure ForcedDropDownList(OpenList :Boolean);
begin
  if OpenList then
  begin
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
    keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), 0, 0);
    keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), KEYEVENTF_KEYUP, 0);
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
  end else
  begin
    keybd_event(VK_ESCAPE, MapVirtualKey(VK_ESCAPE, 0), 0, 0);
    keybd_event(VK_ESCAPE, MapVirtualKey(VK_ESCAPE, 0), KEYEVENTF_KEYUP, 0);
  end;
end;

You can put than in an useful unit in order to be used in others projects.

In order to use, You need to intercept TDBGrid OnColEvent event. We'll need check if dataset is in edit or insert mode before try to dropping-down the pick-list.

Moving from a column to other, the cell is focused but we'll need put it in edit mode in order to gerenerate keyboard events and this is made by setting TDBGrid EditorMode property to True.

So, this is an exemple to use:

procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
  if (DBGrid1.DataSource.State in [dsInsert, dsEdit]) and // check edit/insert mode
     (DBGrid1.SelectedIndex = 1) then // column to applay dropping-down
  begin
    DBGrid1.EditorMode := True;
    ForcedDropDownList(True);
  end;
end;

The dropped pick-list will close only after a choice has been selected or ESCape key pressed - like is normally it occurs.

I hope to help You.

Bye

This article has been dead for over six months. Start a new discussion instead.