Dynamic update color of DBGRID

zhaozj2021-02-11  203

The DBGRID control is a control for displaying a database of many user interfaces. The following programs tell you how to change the display color of the font based on the content displayed. For example, if the population of a city is greater than 2 million, we let it show blue. Used to control events DBGrid.OnDrawColumeCell.procedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); beginif Table1.FieldByName ( 'Population') AsInteger> 20000000 thenDBGrid1. .Canvas.font.color: = CLBLUE; DBGRID1.DEFAULTDRAWCOLUMNCELL (Rect, Datacol, Column, State); END; The above example is simple, but you can expand according to your needs, such as fonts, etc., or even you can Call the drawing function to draw a red circle on the number.

转载请注明原文地址:https://www.9cbs.com/read-4234.html

New Post(0)