delphi - cxGrid : instead of "go to next cell on enter" using "enter" do that with the arrow keys -
is there way can achieve cxgrid's functionality "go next cell on enter" using arrow keys on keyboard instead of hitting "enter" ???
right can navigate arrow keys cells move not selected (blue color). if edit cell in column , move cell beneath (with arrow key) , grid jumps other random record in grid,which annoying.
is question of settings or must program functionality ?
edit : simple temporary table use gather data. has no indexed fields or autoinc field :
procedure tform3.cxbutton1click(sender: tobject); begin datamodule2.acrquery2.close; datamodule2.acrquery2.sql.clear; datamodule2.acrquery2.sql.text :='insert temp select company_id,member_id,surname,name members company_id =:a1'; datamodule2.acrquery2.params.parambyname('a1').value :=cxlookupcombobox2.text; datamodule2.acrquery2.execsql; datamodule2.acrquery3.close; datamodule2.acrquery3.sql.clear; datamodule2.acrquery3.sql.text :='update temp set month=:a1,year=:a2'; datamodule2.acrquery3.params.parambyname('a1').value :=cxcombobox2.text; datamodule2.acrquery3.params.parambyname('a2').value :=cxtextedit2.text; datamodule2.acrquery3.execsql; datamodule2.temp.refresh; end;
data loads when edit first record , move arrow down, cursor jumps end of grid .
navigation arrow key functions normally.i can scroll down column without problem , edit record pause on. edit , move next record, cursor jumps somwhere else. seems sync not function. dont know. not sorting in way .
is question of settings or must program functionality ?
yes, question of settings , doesn't require code. however, there evidently problem in project think need sort out first.
when "the grid jumps other random record in grid,which annoying.", sounds if starting the wrong place try , navigation behaviour want because jumping shouldn't happen. , doesn't in cxgrid project of mine.
anyway, find representation of cxgriddbtableview in object inspector makes hard "see wood trees". use project creates grid entirely in code - see below.
the code below self-contained , doesn't require event handlers, persistent tfields, etc. if try it, should find default, created, grid does support , down , left , right cell navigation using cursor keys. exception left , right keys don't work cell navigation when current cell contents being edited. however, if uncomment line
cxview.datacontroller.options := cxview.datacontroller.options + [dcoimmediatepost];
then, pressing enter
while editing in cell posts edit dataset, , grid will allow navigate out of cell using left- or right-arrow key. i'm sure there fancier ways of achieving effect processing key handling in code, @ least dcoimmediatepost
method has advantage of requiring no code.
when app starts, should see see top row "highlighted" (colored blue default) except lh cell, focused.
hopefully, example identify cause of "jumping" in project , may refine description of obtain, in terms of cursor-key navigation.
code
procedure tform1.creategrid; begin cxgrid := tcxgrid.create(self); cxgrid.parent := self; cxgrid.width := 400; cxlevel := cxgrid.levels.add; cxlevel.name := 'firstlevel'; cxview := cxgrid.createview(tcxgriddbtableview) tcxgriddbtableview; cxview.name := 'atableview'; // uncomment following line make grid respond `enter` key posting pending change data row // cxview.datacontroller.options := cxview.datacontroller.options + [dcoimmediatepost]; cxview.datacontroller.keyfieldnames := 'id'; cxlevel.gridview := cxview; cxview.datacontroller.datasource := ds1; cxview.datacontroller.createallitems; end; function createfield(afieldclass : tfieldclass; aowner : tcomponent; adataset : tdataset; afieldname, aname : string; asize : integer; afieldkind : tfieldkind) : tfield; begin result := afieldclass.create(aowner); result.fieldkind := afieldkind; result.fieldname := afieldname; result.name := aname; result.size := asize; result.dataset := adataset; end; procedure tform1.formcreate(sender: tobject); var : integer; field : tfield; begin field := createfield(tautoincfield, self, cds1, 'id', 'cds1id', 0, fkdata); field := createfield(tbooleanfield, self, cds1, 'marked', 'cds1marked', 0, fkdata); field := createfield(tstringfield, self, cds1, 'name', 'cds1namefield', 20, fkdata); field := createfield(tstringfield, self, cds1, 'value', 'cds1valuefield', 20, fkdata); cds1.createdataset; cds1.indexfieldnames := 'id'; := 1 5 begin cds1.insert; cds1.fieldbyname('marked').asboolean := odd(i); cds1.fieldbyname('name').asstring := 'name' + inttostr(i); cds1.fieldbyname('value').asstring := 'value ' + inttostr(i); cds1.post; end; cds1.first; creategrid; activecontrol := cxgrid; end;
Comments
Post a Comment