Delphi:将Combobox Dropdown添加到TADVStringGrid

时间:2015-05-05 01:28:07

标签: delphi delphi-2006

我有一个有TADVStringGrid的表单。我试图将一个组合框添加到特定列中的某些行(2);但是,我无法在下拉列表中显示数据。我添加了HasComboBox事件,我设置了DirectComboDrop,它仍然没有在下拉列表中显示任何数据。他们只是空的。我检查了我要添加到下拉列表的对象,他们有数据。我在这里缺少什么?

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 个答案:

答案 0 :(得分:0)

需要添加一个名为EditorProp的事件句柄。调用EditorProp事件时,必须添加需要为特定列添加的数据。下面的代码片段被移到了editorprop事件中,从那以后工作正常。

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;