实现既能扫码键入,又能下拉增量搜索的功能
说起来头晕:使用devexpress的TcxDBLookUpComboBox非常方便,但是希望能够进入代码和扫码录入(平板中使用),这就麻烦了。
干货:
1、正常按照增量搜索设置参数;
2、增加设置开关控制:
Properties: DropDownListStyle = lsEditList; ImmediateDropDownWhenKeyPressed = False; GridMode = False;
选用listFieldNames:code+‘’+name。这样可以增量搜索代码和名称。
3、在KeyPress中处理相关:

procedure TFrame_EquipmemtCheck.cbb_QCSTDKeyPress(Sender: TObject; var Key: Char); begin if Key <> #13 then Exit; // 增量搜索模式下,交由系统默认行为处理 if cbb_QCSTD.Properties.ImmediateDropDownWhenKeyPressed then Exit; // 延迟执行,确保 Text 是扫码完整内容 TThread.Queue(nil, procedure var tmpCode, trueCode, displayText: string; begin tmpCode := Trim(cbb_QCSTD.Text); if tmpCode = '' then Exit; // 精确匹配 CODE(而不是 DISPLAYTEXT) if fdmtbl_QCSTANDARD.Locate('CODE', tmpCode, [loCaseInsensitive]) then begin trueCode := fdmtbl_QCSTANDARD.FieldByName('CODE').AsString; displayText := fdmtbl_QCSTANDARD.FieldByName('DISPLAYTEXT').AsString; // 强制赋值:确保控件状态和绑定字段一致 cbb_QCSTD.EditValue := trueCode; cbb_QCSTD.Text := displayText; // 后续业务处理 fdmtbl1.Edit; fdmtbl1.FieldByName('QIC_STD').AsString := trueCode; setCheckListDetail; end else begin // 无匹配项:清空 cbb_QCSTD.EditValue := Null; cbb_QCSTD.Text := ''; fdmtbl1.Edit; fdmtbl1.FieldByName('QIC_STD').Clear; fdmtbl_EquiInsChecklistDetail.EmptyDataSet; end; end); end;
虽然方法很多,但是这样处理感觉比较干净快捷,但是太折腾了。让AI帮助还是死去活来的。