日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

DBGrid应用

發(fā)布時(shí)間:2024/4/15 编程问答 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DBGrid应用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在Delphi語言數(shù)據(jù)庫編程中,DBGrid是顯示數(shù)據(jù)的常用控件之一,下面來介紹一些DBGrid的用法。

1. 獲取DBGrid選中單元格的一些信息

procedure TForm2.DBGrid1CellClick(Column: TColumn); varstrValue:string;iCol,iRow:Integer;rRect:TRect; beginstrValue := DBGrid1.SelectedField.Value; //獲取選中單元格的值iCol := TDrawGrid(DBGrid1).Col; //獲取選擇單元格的列,第一列為1iRow := TDrawGrid(DBGrid1).Row; //獲取選擇單元格的行,第一行為1rRect := TDrawGrid(DBGrid1).CellRect(iCol,iRow); //獲取選擇單元格的矩形框//ShowMessage('行:'+IntToStr(iRow)+#13'列:'+IntToStr(iCol)+#13'值:'+strValue); end;

2. 設(shè)置列名格式,一般列名只需設(shè)置一次(這里一次性繪制所有的列,以避免列數(shù)過多時(shí),顯示滾動(dòng)條后的列時(shí)再繪制時(shí)影響一些正常的操作,譬如按鍵盤方向鍵定位單元格時(shí)可能會(huì)光標(biāo)移到第一行),即可用全局變量進(jìn)行記錄下。

procedure TForm2.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState); vari:Integer; beginif bDrawTitle=False then //一般情況畫一次就夠了,不必重復(fù)畫beginfor i:=0 to DBGrid1.Columns.Count-1 do //一下子繪制所有的列beginif i mod 2 = 0 thenbeginDBGrid1.Columns[i].Title.Font.Color := clRed; //列名 字體顏色DBGrid1.Columns[i].Title.Color := clGreen; //列名 背景DBGrid1.Columns[i].Color := clBlue; //列數(shù)據(jù) 背景end;end;bDrawTitle := True;end;//將數(shù)據(jù)背景斑馬線顯示if CDS1.RecNo mod 2 = 0 thenbegin(Sender as TDBGrid).Canvas.Brush.Color := clGray;end;(Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State); end;

3. 設(shè)置Grid單元格邊框

procedure TForm2.DBGrid1CellClick(Column: TColumn); variCol,iRow:Integer;rRect:TRect; beginiCol := TDrawGrid(DBGrid1).Col; //獲取選擇單元格的列,第一列為1iRow := TDrawGrid(DBGrid1).Row; //獲取選擇單元格的行,第一行為1rRect := TDrawGrid(DBGrid1).CellRect(iCol,iRow); //獲取選擇單元格的矩形框with DBGrid1.Canvas dobeginPen.Width := 4; //設(shè)置畫筆 寬帶Pen.Color := clRed; //設(shè)置畫筆 顏色MoveTo(rRect.Left,rRect.Top); //設(shè)置畫筆 起點(diǎn)LineTo(rRect.Right,rRect.Top); //畫線Pen.Width := 2;Pen.Color := clYellow;MoveTo(rRect.Right,rRect.Top);LineTo(rRect.Right,rRect.Bottom);end; end;

轉(zhuǎn)載于:https://www.cnblogs.com/liuke1987/archive/2013/02/06/2907892.html

總結(jié)

以上是生活随笔為你收集整理的DBGrid应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。