Delphi有很好用的DBNavitor元件,美中不足的是按鈕的樣式稍嫌不足!那是否可以仿DBNavigator的方式?
筆者提供一個簡單的範例給大家 🙂
一、自訂首筆/上筆/下筆/末筆
[pascal]
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
BtnFirst.Enabled := not Datasource1.DataSet.Bof;
BtnPrior.Enabled := not Datasource1.DataSet.Bof;
BtnNext.Enabled := not Datasource1.DataSet.eof;
BtnLast.Enabled := not Datasource1.DataSet.eof;
if TDataSource(Sender).State in [dsEdit,dsInsert] then begin
BtnFirst.Enabled := False;
BtnPrior.Enabled := False;
BtnNext.Enabled := False;
BtnLast.Enabled := False;
end;
end;
[/pascal]
二、自訂新增/修改/刪除/取消/存檔
[pascal]
procedure TForm1.DataSource1StateChange(Sender: TObject);
begin
BtnAdd.Enabled := TDataSource(Sender).State in [dsbrowse];
BtnEdit.Enabled := TDataSource(Sender).State in [dsbrowse];
BtnDelete.Enabled := TDataSource(Sender).State in [dsBrowse];
BtnAbort.Enabled := TDataSource(Sender).State in [dsEdit,dsInsert];
BtnSave.Enabled := TDataSource(Sender).State in [dsEdit,dsInsert];
end;
[/pascal]
三、讓button按下後與DBNavigator一樣
[pascal]
procedure TForm1.BtnAbortClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbcancel);
end;
procedure TForm1.BtnAddClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbinsert);
end;
procedure TForm1.BtnDeleteClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbdelete);
end;
procedure TForm1.BtnEditClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbedit);
end;
procedure TForm1.BtnFirstClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbfirst);
end;
procedure TForm1.BtnLastClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nblast);
end;
procedure TForm1.BtnNextClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbnext);
end;
procedure TForm1.BtnPriorClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbprior);
end;
procedure TForm1.BtnSaveClick(Sender: TObject);
begin
dbnavigator1.BtnClick(nbpost);
end;
[/pascal]