DBGRID column red

Source: Internet
Author: User

DBGRID columns are highlighted in red (used for displaying special data rows, not changed due to RowSelect-> True)

 

Procedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState );
Procedure Drawnumber;
Var
TextWidth: Integer;
TextHeigh: Integer;
Begin
DBGrid1.Canvas. Brush. Color: = clRed;
DBGrid1.Canvas. FillRect (Rect );
DBGrid1.Canvas. Font. Color: = clWhite;
// Set the data redraw position
TextWidth: = DBGrid1.Canvas. TextWidth (Column. Field. AsString );
TextWidth: = Rect. Left + (Rect. Right-Rect.Left)-TextWidth-3;
TextHeigh: = DBGrid1.Canvas. TextHeight (Column. Field. AsString );
TextHeigh: = Rect. Top + (Rect. Bottom-Rect.Top-TextHeigh) div 2;
DBGrid1.Canvas. TextOut (TextWidth, TextHeigh, Column. Field. AsString );
End;
Procedure DrawText (Field: TField; Rect: TRect );
Var
TextWidth: Integer;
TextHeigh: Integer;
Leng: Integer;
Begin
Leng: = DBGrid1.Columns [2]. Width + 1;
Rect. Right: = Rect. Left;
Rect. Left: = Rect. Left-leng;

DBGrid1.Canvas. Brush. Color: = clRed;
DBGrid1.Canvas. FillRect (Rect );
DBGrid1.Canvas. Font. Color: = clWhite;
// Set the data redraw position
TextWidth: = Rect. Left + 1;
TextHeigh: = DBGrid1.Canvas. TextHeight (Field. AsString );
TextHeigh: = Rect. Top + (Rect. Bottom-Rect.Top-TextHeigh) div 2;
DBGrid1.Canvas. TextOut (TextWidth, TextHeigh, Field. AsString );
End;
Begin
If (Drawing) and (DataCol = 3) and
(Column. Field. DataSet. FieldByName ('subobject'). AsString = ComboBox1.Text) then
Begin
Case ComboBox2.ItemIndex
0: begin
If Column. Field. AsInteger> StrToInt (Edit1.Text) then
Begin
Drawnumber;
DrawText (Column. Field. DataSet. FieldByName ('subobject'), Rect );
End;
End;
1: begin
If Column. Field. AsInteger <StrToInt (Edit1.Text) then
Begin
Drawnumber;
DrawText (Column. Field. DataSet. FieldByName ('subobject'), Rect );
End;
End;
2: begin
If Column. Field. AsInteger = StrToInt (Edit1.Text) then
Begin
Drawnumber;
DrawText (Column. Field. DataSet. FieldByName ('subobject'), Rect );
End;
End;
End;
End
Else
Begin
Dbgrid1.defadrawcolumncell (Rect, DataCol, Column, State );
End;
End;

Procedure TForm1.GetSubject;
Var
I: Integer;
Begin
With DMFrm. ADOCommand do
Begin
Active: = False;
CommandText: = 'select Subject From StudentGrade_Tab Group By subobject ';
Active: = True;
ComboBox1.Clear;
For I: = 0 to RecordCount-1 do
Begin
ComboBox1.Items. Add (FieldByName ('subobject'). AsString );
Next;
End;
End;
End;

Procedure TForm1.FormCreate (Sender: TObject );
Begin
GetSubject;
End;

Procedure TForm1.BitBtn1Click (Sender: TObject );
Begin
If (ComboBox1.Text <> '') and
(ComboBox2.Text <> '') and
(Edit1.Text <> '') then
Begin
Drawing: = True;
DBGrid1.Refresh;
End;
End;

 

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.