如何在TcxExtLookupComboBox中使用TcxCustomDataSource? [英] How to use a TcxCustomDataSource in a TcxExtLookupComboBox?
问题描述
我使用来自Devexpress的TcxExtLookupComboBox并尝试实现自定义数据源。我已经这样设置了customdatasource:
I use a TcxExtLookupComboBox from Devexpress and try to implement a custom datasource. I have set the customdatasource like this:
procedure TMainForm.FormCreate(Sender: TObject);
begin
fDataSource := TMyDataSource.Create;
cbotestSearch.Properties.View.DataController.CustomDataSource := fDataSource;
end;
TMyDataSource在这里定义:
TMyDataSource is defined here:
unit Datasource;
interface
uses
Classes,
IBQuery,
SysUtils,
cxCustomData;
type
TSearchItem = class
private
BoldID: String;
Display: String
end;
TMyDataSource = class(TcxCustomDataSource)
private
fSearchList: TList;
protected
function GetRecordCount: Integer; override;
function GetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle): Variant; override;
public
constructor Create;
destructor Destroy; override;
procedure GetData;
end;
implementation
constructor TMyDataSource.Create;
begin
inherited Create;
fSearchList := TList.Create;
end;
destructor TMyDataSource.Destroy;
begin
FreeAndNil(fSearchList);
inherited;
end;
procedure TMyDataSource.GetData;
var
vItem: TSearchItem;
begin
fSearchList.Clear;
vItem := TSearchItem.Create;
vItem.BoldID := '1000';
vItem.Display := 'test';
fSearchList.Add(vItem);
vItem := TSearchItem.Create;
vItem.BoldID := '1100';
vItem.Display := 'test2';
fSearchList.Add(vItem);
DataChanged; // Don't do anything as provider is nil
end;
function TMyDataSource.GetRecordCount: Integer;
begin
// Is never entered
Result := fSearchList.Count;
end;
function TMyDataSource.GetValue(ARecordHandle: TcxDataRecordHandle;
AItemHandle: TcxDataItemHandle): Variant;
begin
// Is never entered
Result := 'Test';
end;
end.
问题是从不调用TMyDataSource.GetValue。任何提示如何解决?
The problem is that TMyDataSource.GetValue is never called. Any hint how to fix ?
更新1:我在这里还有另一个提示。如果我单步执行应该导致GetValue调用的DataChanged方法,则如下所示:
Update 1: I have another hint here. If I single step in the DataChanged method that should cause GetValue to be called is looks like this:
procedure TcxCustomDataSource.DataChanged;
begin
if Provider = nil then Exit;
// Code using Provider
end;
,在这种情况下,提供者为零。但是,正如您所见,我已将数据源分配为oncreate形式。
and Provider is nil in this case. But I have assigned the Datasource in Forms oncreate as you see.
推荐答案
cxExtLookupComboBox仅可用于DB〜视图。这样的视图不能接受TcxCustomDataSource对象的实例作为数据源。因此,您的代码将不起作用:-(。将来有实现此功能的建议,并且它已在以下位置注册:
cxExtLookupComboBox can only work with DB~views. Such views cannot accept instances of the TcxCustomDataSource object as a DataSource. So, your code will not work :-(. There is a suggestion to implement this feature in the future and it is registered at:
http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=AS10025
这篇关于如何在TcxExtLookupComboBox中使用TcxCustomDataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!