Dev Express 是外掛的套件,須要另外安裝才會出現。

一、先將ADO連線、ADO Query 與 DataSource 等元件設定好。(這個每本書都會教到,所以不多說)

二、拉入 Dev Express 的 cxGrid 元件,點選 cxGrid1DBTableView1 後到左邊屬性設定DataSource。

1

三、建立 FormCreate 程序

procedure TForm1.FormShow(Sender: TObject);
begin
cxGrid1DBtableView1.CreateColumn; //創建一個欄位
cxGrid1DBtableView1.Columns[0].DataBinding.FieldName := 'Serial'; //cxGrid第一個欄位(Columns[0])抓取對應到 DataSource 內 Serial 欄位資料內容(與查詢的TABLE欄位名稱要一致)
cxGrid1DBtableView1.Columns[0].Caption := '序號'; //自訂秀在表格上的欄位名稱,若沒設定預設自動代查詢後的欄位名稱 Serial
cxGrid1DBtableView1.Columns[0].Width := 35; //給訂欄寬
cxGrid1DBtableView1.CreateColumn;//創建二個欄位
cxGrid1DBtableView1.Columns[1].DataBinding.FieldName := 'ProgId';//cxGrid第二個欄位(Columns[1])抓取對應到 DataSource 內 ProgId 欄位資料內容(與查詢的TABLE欄位名稱要一致)
cxGrid1DBtableView1.Columns[1].Caption := '程序編號'; //自訂秀在表格上的欄位名稱,若沒設定預設自動代查詢後的欄位名稱 ProgId
cxGrid1DBtableView1.Columns[1].Width := 60; //給訂欄寬

cxGrid1DBtableView1.CreateColumn;
cxGrid1DBtableView1.Columns[2].DataBinding.FieldName := 'GdsNo';
cxGrid1DBtableView1.Columns[2].Caption := '貨物號碼';
cxGrid1DBtableView1.Columns[2].Width := 60;

ADOQuery1.Open;
end;

以上程式啟動後就會看到下面的效果,每個欄位如果對應沒問題,資料都會自動抓進來。灰色可以將欄位托曳進去,不過這部份暫時還找不出怎樣拿掉。

2

找到取消灰色部份的方式了,感謝Delphi K.Top討論區 Jasonwong 大大解惑

3

arrow
arrow
    全站熱搜

    NoMoney NoHoney 發表在 痞客邦 留言(0) 人氣()