delphi cxgrid +toolBar做一个紧贴表头的条件搜索框
效果图:
type TFrame2 = class(TFrame) Panel1: TPanel; TV: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; cxGrid1: TcxGrid; TVColumnName: TcxGridDBColumn; TVColumnAge: TcxGridDBColumn; TVColumnAddress: TcxGridDBColumn; scToolBar1: TscToolBar; Edit2: TEdit; Edit3: TEdit; Edit1: TEdit; procedure FrameResize(Sender: TObject); private { Private declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; procedure ToResize(); end; implementation {$R *.dfm} constructor TFrame2.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Align := alClient; end; procedure TFrame2.FrameResize(Sender: TObject); begin ToResize(); end; procedure TFrame2.ToResize(); var w1, w2, w3: Integer; begin
//注意红色部分.如果直接使用TVColumnName.Width 只能取到列的预设宽度 w1 := TV.ViewInfo.HeaderViewInfo.Items[TVColumnName.Index].Width; Edit1.width := w1; Edit1.Text := 'name: ' + w1.ToString; w2 := TV.ViewInfo.HeaderViewInfo.Items[TVColumnAge.Index].Width; Edit2.width := w2; Edit2.Text := 'age: ' + w2.ToString; w3 := TV.ViewInfo.HeaderViewInfo.Items[TVColumnAddress.Index].Width; Edit3.width := w3; Edit3.Text := 'address: ' + w3.ToString; end;