Montag, 3. April 2017

Lazarus databasegrid and multiselect with mouse click on the indicator column.

Normally lazarus allow multiple selection of rows only with [ctrl-key]+left-mouse-button.
If you want to allow user selecting multiple rows without holding [ctrl]-Key then do this:
1. Open lazarus/lcl/grids.pas
2. Edit MouseDown procedure and make this changes:


procedure TCustomDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
var
  sonMouseInCol: integer; //ADD
//...

        P:=MouseToCell(Point(X,Y));
        sonMouseInCol:=P.X; //ADD
        if Gz=gzFixedRows then

//...
            if (Button=mbLeft) and((sonMouseInCol<>0)and(dgIndicator in Options)) then //CHANGE
              ClearSelection(true)
            else ToggleSelectedRow; //ADD
            if gz=gzFixedRows then
//..
            if (Button=mbLeft) and((sonMouseInCol<>0)and(dgIndicator in Options)) then //CHANGE
              ClearSelection(true)
            else ToggleSelectedRow; //ADD
            doMoveToColumn;
end; 


I indicated changes with red color other lines shows you where to make changes or add new code.

Now the user will be able to select multiple rows only with mouse click on the indicator column.
Of course you have to add dgMultiselect in TDBGrid.Options too.

Keine Kommentare:

Kommentar veröffentlichen