Search code examples
delphidelphi-2006

Delphi TMS Grids Moving to Next Column After User Select Value in Dropdown


I have a Delphi 2006 application that has TAdvStringGrid. There is one column in the Grid where I have to display a dropdownbox. It worked fine but I am not able to move the cursor to the next column in the grid. The column that I want to move to is selected, but the focus is still on the dropdown. Here is how it's supposed to work. The user will enter a number, and I will display the item associated with the index that the user type. If the user type the item name, I will look for the item in the dropdown. In both cases, if the user enter a correct value, I want to move to the next column in the grid. If entered value does not exit, I tell the user that it's invalid.

   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;

Solution

  • I had to add to add 2 events for this to work properly. I added an onHasCombobox event and a OnGetEditorProp event. I always return true for column 5 in the onHasCombobox event which is where I needed the comboboxes. Then, when a dropdown is clicked, it called the OnGetEditorProp which then display the data that I need to display on the dropdown.