delphi - Put a devexpress dbgridview cell's contents with different textformats -
with devexpress cxgrid, i've tablegridview showing db table of 3 fields of varchar(30); id, name , description
actual cxgrid appearance : id name description 1 name 1 description 1 2 name 2 description 2 . ... ... x name x description 3
and, want 2 fields concatenated , separated #13 (in 2 lines), , each line special text format (ex. 1st bold , 2nd italic).
the cxgrid's appearance : id name , description (just 1 field instead of two) 1 name 1 description 1 2 name 2 description 2 . name ... description ... 3 name 3 description ...
any appreciated !
i have tried both possibilities suggested in comments, i.e. using custom drawing in standard dbtableview , using dbbandedtableview , neither seems offer ideal solution out of box.
using dbtableview runs sand non-expert me:
- although straightforward draw
descriptiontext belownametext, fraught difficulties, how pick bounds ofnamecell while drawingdescription1 , how avoid grid drawing residual outline of have beendescriptioncell , header ifdescriptiondrawn normally.
using dbbandedtableview seems converge on workable solution far fewer details address. try following:
add clientdataset,
cds1form, add persistent fields id, name , description fields.add dbbandedtableview cxgrid , connect
cds1using tdatasource.create 2 bands in , give them captions
band,band2ease of reference.create columns
id,name,descriptioncolumns. setpropertiesproperty textedit.in dbbandedtableview editor, add
idcolumnband,name,descriptioncolumnsband2usingbandindexsub-property of columns'positionproperty. setrowindexsub-property ofdescriptioncolumn 1, cause positioned belownamefield.
set form's code shown below, compile , run. can see, custom drawing code set font style of name , description fields.
the result maybe not quite you've specified, i'll leave iron out remaining details - if stuck, so.
type tform1 = class(tform) cds1: tclientdataset; cds1id: tautoincfield; ds1: tdatasource; dbnavigator1: tdbnavigator; cds1name: tstringfield; cds1description: tstringfield; cxgrid1level1: tcxgridlevel; cxgrid1: tcxgrid; cxgrid1dbbandedtableview1: tcxgriddbbandedtableview; cxgrid1dbbandedtableview1id: tcxgriddbbandedcolumn; cxgrid1dbbandedtableview1name: tcxgriddbbandedcolumn; cxgrid1dbbandedtableview1description: tcxgriddbbandedcolumn; procedure formcreate(sender: tobject); private procedure customdrawcell( sender: tcxcustomgridtableview; acanvas: tcxcanvas; aviewinfo: tcxgridtabledatacellviewinfo; var adone: boolean); protected public end; var form1: tform1; [...] procedure tform1.customdrawcell(sender: tcxcustomgridtableview; acanvas: tcxcanvas; aviewinfo: tcxgridtabledatacellviewinfo; var adone: boolean); var acol : tcxgriddbbandedcolumn; begin acol := tcxgriddbbandedcolumn(aviewinfo.item); if acol = cxgrid1dbbandedtableview1name acanvas.font.style := acanvas.font.style + [fsbold] else if acol = cxgrid1dbbandedtableview1description acanvas.font.style := acanvas.font.style + [fsitalic]; end; procedure tform1.formcreate(sender: tobject); var : integer; begin cds1.createdataset; cds1.insertrecord([1, 'name1', 'description1']); cds1.insertrecord([2, 'name12', 'description2']); cds1.first; cxgrid1dbbandedtableview1id.propertiesclassname := 'tcxtexteditproperties'; cxgrid1dbbandedtableview1id.oncustomdrawcell := customdrawcell; cxgrid1dbbandedtableview1name.propertiesclassname := 'tcxtexteditproperties'; cxgrid1dbbandedtableview1name.oncustomdrawcell := customdrawcell; cxgrid1dbbandedtableview1description.propertiesclassname := 'tcxtexteditproperties'; cxgrid1dbbandedtableview1description.oncustomdrawcell := customdrawcell; end; end.
Comments
Post a Comment