How can I add the record number to DBGrid?

Source: Internet
Author: User
How can I add the record number to DBGrid? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061223091242150.html
Which of the following is displayed in my DBGrid? Code , How to add the record number to the DBGrid column? Thank you!
Qq1: = tadoquery. Create (Self );
Qq1.connection: = conn;
With qq1 do
Begin
Close;
SQL. Clear;
SQL. Add ('select ID, haoma as number, guishu as region, tongxunming as communication company from haoma ');
Open;
End;
Performance1.dataset: = qq1;
Dbgrid1.datasource: = performance1;

Isn't ID a record number?

ID is only an automatic number in the database, not necessarily from 1, followed by the order of 1

{Overwrite the drawcell event and display the Row No}
Procedure tdbgrideh. drawcell (ACOl: integer; Arow: integer; arect: trect; astate: tgriddrawstate );
VaR
I, dbrow, lleft: integer;
Icol, irow: integer; // global variable
Begin
Inherited;

{Whether to enable the row number display function !}
If fshowrecno = true then
Begin
If assigned (datalink) and
Datalink. Active then // No open
Begin
If (Arow> = 1) and
(ACOl = 0) Then {within the row header}
Begin
I: = 0; // Offset Value
Lleft: = 0; // center display
Dbrow: = self. datasource. dataset. recno; // row mark Rec No for the current Dataset
If datasource. dataset. recno =-1 then {New Record status}
Begin
Dbrow: = datasource. dataset. recordcount + 1; // The total number of records marked by the current row + 1
End;
I: = dbrow-self. Row; // calculates the Offset Value of the table toprow and the row where the dataset is located (displays the actual dataset row number)
Lleft: = (arect. Right-arect. Left) Div 2-canvas. textwidth (inttostr ({datalink. activerecord} Arow + I) Div 2; // center display
Canvas. textrect (arect, arect. Left + lleft, arect. Top, inttostr ({datalink. activerecord} Arow + I); // output row number
End;
End;
End;
End;


There is a complete control, which is very easy to use!

Leave an email and I will send it to you. Or add my QQ: 67016879

1. Add a column to DBGrid. For example, the column name header is 'sequence number'
2. Code:

Procedure tform1.dbgrid1drawcolumncell (Sender: tobject; const rect: trect;
Datacol: integer; column: tcolumn; State: tgriddrawstate );
Begin
If performance1.dataset. recno> 0 then
Begin
If wideuppercase (column. Title. Caption) = 'sequence number 'then
Dbgrid1.canvas. textout (rect. Left + 2, rect. Top, inttostr (performance1.dataset. recno ));
End;
End;

Very troublesome.

Paste

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.