delphi - DBGrid: how to prevent a row from being selected? -
i have grid of entries user click on multi-select process. of entries invalid based upon values of first selected row.
i know dbgrid.selectedrows.currentrowselected
, cannot find suitable place checking conditions set true or false.
something this:
var bm: tbookmark; cachedidentity: string; canselect: boolean; begin dgbskypeconversations begin if selectedrows.count > 0 begin datasource.dataset.disablecontrols; bm := datasource.dataset.getbookmark; cachedidentity := datasource.dataset.fieldbyname('identity').asstring; datasource.dataset.gotobookmark(selectedrows[0]); canselect := datasource.dataset.fieldbyname('identity').asstring <> cachedidentity; datasource.dataset.gotobookmark(bm); datasource.dataset.freebookmark(bm); selectedrows.currentrowselected := canselect; datasource.dataset.enablecontrols; end; end end;
i have tried onmousedown
events in application.onmessage
, of dbgrid , form, not work, , there no tbookmarklist.beforeinsertitem
event. can or must change?
i not make complicated.
if comparison takes place on first selection.
code use here has hardcoded value.
no jump around bookmarks.
// first selection----------------------------- if dbgrid1.selectedrows.count = 1 begin cachedidentity := 'sonnenbrille'; // sunglasses //cachedidentity := datasource.dataset.fieldbyname('identity').asstring; exit; end;
do comparison
if dbgrid1.selectedrows.currentrowselected begin //if cachedidentity <> datasource.dataset.fieldbyname('identity').asstring if pos(lookingfor,dbgrid1.datasource.dataset.fieldbyname('haupttxt').asstring)=0 dbgrid1.selectedrows.currentrowselected := false; showmessage(inttostr(dbgrid1.selectedrows.count)); end;
we can see 2 selected so
showmessage(inttostr(dbgrid1.selectedrows.count));
shows 2
now want select line
sportlich, elegante gucci sonnenbrille
we know simple pos() sonnenbrille
find sonnenbrille
pos() = 0, selection-will not take place.
showmessage(inttostr(dbgrid1.selectedrows.count));
shows 2 too
code:
var cachedidentity : string; procedure tform2.canselectedv1; begin // first selection----------------------------- if dbgrid1.selectedrows.count = 1 begin cachedidentity := 'sonnenbrille'; // sunglasses //cachedidentity := datasource.dataset.fieldbyname('identity').asstring; exit; end; if dbgrid1.selectedrows.currentrowselected begin //if cachedidentity <> datasource.dataset.fieldbyname('identity').asstring if pos(lookingfor,dbgrid1.datasource.dataset.fieldbyname('haupttxt').asstring)=0 dbgrid1.selectedrows.currentrowselected := false; showmessage(inttostr(dbgrid1.selectedrows.count)); end; end; procedure tform2.dbgrid1mouseup(sender: tobject; button: tmousebutton; shift: tshiftstate; x, y: integer); begin canselectedv1; end; procedure tform2.dbgrid1keyup(sender: tobject; var key: word; shift: tshiftstate); begin canselectedv1; end; end.
Comments
Post a Comment