Delphi Combobox自动选择项及触发onchange事件

2中方法:

1.

StrngLst := TStringList.Create;
    StrngLst.Clear;
    SplitColumns(strngrdProgram.Cells[2,strngrdProgram.Selection.Top],StrngLst,';');
    for i := 0 to StrngLst.Count - 1 do
    begin
      SendMessage(cbbAccessory.Handle,CB_SETCURSEL, cbbAccessory.Items.IndexOf(StrngLst[i]), 0);  //选择行
      SendMessage(cbbAccessory.Handle,CN_COMMAND,MakeLong(0,CBN_SELCHANGE),0); //当前行触发onchange事件
    end;


2.

StrngLst := TStringList.Create;
    StrngLst.Clear;
    SplitColumns(strngrdProgram.Cells[2,strngrdProgram.Selection.Top],StrngLst,';');
    for i := 0 to StrngLst.Count - 1 do
    begin
      cbbAccessory.ItemIndex := cbbAccessory.Items.IndexOf(StrngLst[i]);  //选择行
      SendMessage(cbbAccessory.Handle,CN_COMMAND,MakeLong(0,CBN_SELCHANGE),0); //当前行触发onchange事件
    end;



你可能感兴趣的:(Delphi)