如果它有帮助,下面是一个极简 cxGrid 项目的代码和 DFM,它对我来说很好,并且没有显示你描述的行为。如果它也适用于您,也许它会帮助您确定项目中的哪些差异导致了您的问题。
代码:
type
TForm1 = class(TForm)
CDS1: TClientDataSet;
DataSource1: TDataSource;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
CDS1ID: TIntegerField;
CDS1Name: TStringField;
cxGrid1DBTableView1ID: TcxGridDBColumn;
cxGrid1DBTableView1Name: TcxGridDBColumn;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
protected
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i,
j,
ID : Integer;
Name : String;
begin
CDS1.CreateDataSet;
for i := 1 to 26 do begin
for j:= 1 to 26 do begin
ID := i * j;
Name := Chr(Ord('A') + i - 1) + Chr(Ord('A') + j - 1);
CDS1.InsertRecord([ID, Name]);
end;
end;
CDS1.First;
Caption := IntToStr(CDS1.RecordCount);
cxGrid1DBTableView1.DataController.Filter.BeginUpdate;
try
cxGrid1DBTableView1.DataController.Filter.Root.AddItem(cxGrid1DBTableView1Name, foLike, '%A', '%A');
finally
cxGrid1DBTableView1.DataController.Filter.EndUpdate;
cxGrid1DBTableView1.DataController.Filter.Active := true;
end;
end;
DFM:
object Form1: TForm1
Left = 259
Top = 103
AutoScroll = False
Caption = 'Form1'
ClientHeight = 314
ClientWidth = 444
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
Scaled = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object cxGrid1: TcxGrid
Left = 0
Top = 0
Width = 444
Height = 314
Align = alClient
TabOrder = 0
object cxGrid1DBTableView1: TcxGridDBTableView
Navigator.Buttons.CustomButtons = <>
DataController.DataSource = DataSource1
DataController.KeyFieldNames = 'ID'
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
FilterRow.Visible = True
OptionsView.GroupByBox = False
object cxGrid1DBTableView1ID: TcxGridDBColumn
DataBinding.FieldName = 'ID'
end
object cxGrid1DBTableView1Name: TcxGridDBColumn
DataBinding.FieldName = 'Name'
end
end
object cxGrid1Level1: TcxGridLevel
GridView = cxGrid1DBTableView1
end
end
object CDS1: TClientDataSet
Aggregates = <>
IndexFieldNames = 'Name'
Params = <>
Left = 16
Top = 24
object CDS1ID: TIntegerField
FieldName = 'ID'
end
object CDS1Name: TStringField
FieldName = 'Name'
Size = 40
end
end
object DataSource1: TDataSource
DataSet = CDS1
Left = 56
Top = 24
end
end