Recent

Author Topic: [SOLVED]: RxDBGrid: how to get index of the column with the changed width?  (Read 1887 times)

zoltanleo

  • Hero Member
  • *****
  • Posts: 515
Friends, need your help.

I need to get the index column of the grid until the mouse button is pressed.

OnColumnSized allows you to do only after releasing кнопки
OnKeyDown allows you to get only the Row of the grid, if you click between the columns.

I would be grateful for advice and code examples.
« Last Edit: December 22, 2016, 11:53:55 am by zoltanleo »
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

zoltanleo

  • Hero Member
  • *****
  • Posts: 515
Re: RxDBGrid: how to get index of the column with the changed width?
« Reply #1 on: December 22, 2016, 11:53:28 am »
   
Code: Pascal  [Select][+][-]
  1.  function TForm1.ColNumIsResized(Sender: TRxDBGrid; Shift: TShiftState; X,
  2.       Y: Integer; out AColNum: Integer): Boolean;
  3.     const
  4.         OffSetMargin: Integer =2;
  5.       var
  6.         Col, Row, ColNum : Longint;
  7.  
  8.         XX, YY, IndWidth, total, i : Integer;
  9.       ColMargArray: Array of Integer;
  10.     begin
  11.       AColNum:= -1;
  12.       Result:= False;
  13.  
  14.       XX:=TRxDBGrid(Sender).ScreenToClient(Mouse.CursorPos).X;
  15.       YY:=TRxDBGrid(Sender).ScreenToClient(Mouse.CursorPos).Y;
  16.       TRxDBGrid(Sender).MouseToCell(xx,yy,Col,Row);
  17.  
  18.       if (Row > 0) then Exit;
  19.       if not (ssLeft in Shift) then Exit;
  20.  
  21.  
  22.       if dgIndicator in TRxDBGrid(Sender).Options
  23.         then
  24.           begin
  25.             IndWidth:= IndicatorWidth;
  26.             ColNum:= Col - 1;
  27.           end
  28.         else
  29.           begin
  30.             IndWidth:= 0;
  31.             ColNum:= Col;
  32.           end;
  33.  
  34.       total:= IndWidth;
  35.  
  36.       SetLength(ColMargArray,TRxDBGrid(Sender).Columns.Count);
  37.  
  38.  
  39.       for i := 0 to Pred(TRxDBGrid(Sender).Columns.Count) do
  40.         begin
  41.           total:= total + TRxDBGrid(Sender).Columns.Items[i].Width;
  42.  
  43.           if (i = Pred(TRxDBGrid(Sender).Columns.Count))
  44.             then
  45.               ColMargArray[i]:= total - 1
  46.             else
  47.               ColMargArray[i]:= total;
  48.         end;
  49.  
  50.  
  51.       if ColNum >= 0 then
  52.         begin
  53.           if TRxDBGrid(Sender).Columns.Count = 1 then
  54.             begin
  55.               AColNum:= 0;
  56.               Result:= True;
  57.               Exit;
  58.             end;
  59.  
  60.           for i := Low(ColMargArray) to High(ColMargArray) do
  61.             if (XX = ColMargArray[i]) then
  62.               begin
  63.                 AColNum:= i;
  64.                 Break;
  65.               end;
  66.          
  67.           if AColNum = -1 then
  68.             begin
  69.               if ColNum = Low(ColMargArray)
  70.                 then
  71.                   begin
  72.                    if ((ColMargArray[ColNum] - XX) <= OffSetMargin)
  73.                      then
  74.                        AColNum:= ColNum;
  75.                   end
  76.                 else
  77.                   if ColNum = High(ColMargArray)
  78.                     then
  79.                       begin
  80.                        if (XX - ColMargArray[ColNum-1]) <= OffSetMargin
  81.                           then
  82.                             AColNum:= (ColNum - 1);
  83.  
  84.                         if ((ColMargArray[ColNum] - XX) <= (OffSetMargin - 1))
  85.                           then
  86.                             AColNum:= ColNum;
  87.                       end
  88.                     else
  89.                       begin
  90.                         if (XX - ColMargArray[ColNum-1]) <= OffSetMargin
  91.                           then
  92.                             AColNum:= (ColNum - 1);
  93.                         if ((ColMargArray[ColNum] - XX) <= OffSetMargin)
  94.                           then
  95.                             AColNum:= ColNum;
  96.                       end;
  97.             end;
  98.         end;
  99.  
  100.       Result:= (AColNum >= 0);
  101.     end;
 

Used
Code: Pascal  [Select][+][-]
  1.     procedure TForm1.rxgridMouseMove(Sender: TObject; Shift: TShiftState; X,
  2.       Y: Integer);
  3.     var Col: Integer;
  4.     begin
  5.     with Memo1 do
  6.     begin
  7.       Clear;
  8.       if ColNumIsResized(rxgrid,Shift,x,y,Col)
  9.         then
  10.           Lines.Add(Format('Col = %d',[Col]))
  11.         else
  12.           begin
  13.             Clear;
  14.             Lines.Add('resizing is unavailable');
  15.           end;
  16.     end;
  17.     end;


                                                                   
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

 

TinyPortal © 2005-2018