delphi - cxgrid highlight (or color) changed cell on form closequery -
on closequery of form have :
if messagedlg('close program ?', mtconfirmation, [mbyes,mbcancel],0) <> mryes canclose := false else if datamodule2.mytable.state in [dsedit,dsinsert] if messagedlg('save changes ?', mtconfirmation, [mbyes,mbno],0) = mryes datamodule2.mytable.post;
is there way can highlight (or color) changed cell in cxgrid when trigger onclosequery event ?
i don't need know changed know cell changed user can see can decide weather save changes or not.
it simple cxgrid draw cell (or row) highlighted in way using cxgrid1dbtableview1customdrawcell
event. , having flag indicates onclosequery event in progress, can restrict action inside event.
update code posted answer not mark more 1 cell in current grid row changed. updated code below can however; note comments in 2 procedures.
type tform1 = class(tform) [...] public queryingclose : boolean; end; procedure tform1.formclosequery(sender: tobject; var canclose: boolean); begin try queryingclose := true; //{cxgrid1.invalidate{true); not call invalidate, because causes // grid's repainting logic operate in way makes // impossible mark more 1 cell in current data row changed showmessage('close?'); queryingclose := false; end; end; procedure tform1.cxgrid1dbtableview1customdrawcell(sender: tcxcustomgridtableview; acanvas: tcxcanvas; aviewinfo: tcxgridtabledatacellviewinfo; var adone: boolean); var field : tfield; markcell : boolean; s1, s2 : string; ec : tcxgridtableeditingcontroller; begin if queryingclose , (tcxgriddbtableview(sender).datacontroller.dataset.state in[dsedit, dsinsert]) begin field := tcxgriddbcolumn(aviewinfo.item).databinding.field; s1 := vartostr(field.oldvalue); // when event called, user may in middle of editing cell's contents // so, purpose of following lines close inplace editor being used // amd post chamged value tfield associated cell ec := tcxgriddbtableview(sender).controller.editingcontroller; if ec.isediting ec.hideedit(true); s2 := vartostr(field.value); markcell := s1 <> s2; if markcell acanvas.brush.color := cllime; end; end;
for work, tdataset-descendant type must support correctly returning original contents of fields on oldvalue property; tclientdataset, i've used write/test code i've no idea actual tdataset type you're using.
hopefully, should apparent use these 2 procedures build list of tfields have changed values, including fieldname oldvalue, , value.
Comments
Post a Comment