Delphi: Adding Combobox Dropdown to TADVStringGrid

2.6k Views Asked by At

I have a form that has a TADVStringGrid. I am trying to add a combobox to some rows in a specific column (2); however, I can't get the data to show on the dropdown. I added the HasComboBox event, I set the DirectComboDrop, and it still did not show any data in the dropdown. They were just empty. I check the object that I am adding to the dropdown, and they had data. What am I missing here?

procedure UserForm.DisplayGrid(Sender: TObject);
var  
 J      : Integer;
begin
 ... additional logic
 ...  
if OutputList.Count > 2 then
begin
  with UserGrid.Combobox do
       begin
        for J := 0 to OutputList.Count - 1 do
        BEGIN
         if not(OutputList[J] = '') then
         begin
         dValue  :=  DropDownValue.Create;
         dValue.ID := J + 1;
         dvalue.Name      := OutputList[J];
         dvalue.TestValue := OutputList[J] + 'testvalue'; // where value will be a list to choose from
         ListOfTest.Add(dValue); // this is a glabal variable where I for later reference
          ItemIndex := dValue.ID;
         end;
        END;
end;
end;



//event
procedure UserForm.UserGridHasComboBox(Sender: TObject; ACol, ARow: Integer;
  var HasComboBox: Boolean);
begin
  HasComboBox := True;
end;
1

There are 1 best solutions below

0
Denes On BEST ANSWER

There is an event handle called EditorProp that needed to be added. Data that need to be added for a specific column have to be added when the EditorProp event is called. The piece of code below was moved into the editorprop event, and it's working fine since.

for J := 0 to OutputList.Count - 1 do
        BEGIN
         if not(OutputList[J] = '') then
         begin
         dValue  :=  DropDownValue.Create;
         dValue.ID := J + 1;
         dvalue.Name      := OutputList[J];
         dvalue.TestValue := OutputList[J] + 'testvalue'; // where value will be a list to choose from
         ListOfTest.Add(dValue); // this is a glabal variable where I for later reference
          ItemIndex := dValue.ID;
         end;