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