用户在下拉列表中选择值后,Delphi TMS网格移动到下一列

时间:2015-05-01 17:34:58

标签: delphi delphi-2006

我有一个包含TAdvStringGrid的Delphi 2006应用程序。网格中有一列我必须显示一个下拉框。它工作正常,但我无法将光标移动到网格中的下一列。我要移动的列已被选中,但重点仍在下拉列表中。 这是它应该如何工作的。用户将输入一个数字,我将显示与用户键入的索引相关联的项目。如果用户键入项目名称,我将在下拉列表中查找该项目。在这两种情况下,如果用户输入正确的值,我想移动到网格中的下一列。如果输入的值没有退出,我告诉用户它无效。

   E := 0;
    if (tcxDisplayOption.Visible = True) then
    begin
      if (OutPutList.Count > 1) then
       begin
        TryStrToInt(tcxDisplayOption.Text, E) ;
        if (E > 0 ) and ( E <= tcxDisplayOption.Properties.Items.Count - 1)   then
        BEGIN
         tcxDisplayOption.ItemIndex := tcxDisplayOption.Properties.Items.IndexOf(tcxDisplayOption.Properties.Items[E]);
         TestGrid.SetFocus;
         TestGrid.EditMode := true;
         TestGrid.SelectedCells[2,currentRow];
         TestGrid.EditCell(2,currentRow);
        END
        else if (E = 0) and (Length(tcxDisplayOption.Text) > 1) then
         begin
         index := tcxDisplayOption.Properties.Items.IndexOf(tcxDisplayOption.Text);
         if not (index = -1) then
         begin
         TestGrid.SetFocus;
         TestGrid.EditMode := true;
         TestGrid.SelectedCells[2,currentRow];
         TestGrid.EditCell(2,currentRow);
         end
         else
         begin
          ShowMessage('Not a vaild option.');
         end;
         end
         else
         begin
           ShowMessage('Not a valid option.');
         end;
       end;
    end;

1 个答案:

答案 0 :(得分:0)

我必须添加以添加2个事件才能正常工作。我添加了一个onHasCombobox事件和一个OnGetEditorProp事件。我总是在onHasCombobox事件的第5列返回true,这是我需要组合框的地方。然后,当单击下拉列表时,它会调用OnGetEditorProp,然后显示我需要在下拉列表中显示的数据。