Home > other >  Delphi Firemonkey Grid component scrolling
Delphi Firemonkey Grid component scrolling

Time:02-03

I am using firemonkey Delphi. I have a Grid component and several edit boxes within a Listbox, each component occupying their own listboxitem within the listbox. My question is, when I scoll the listbox and my mouse moves over the grid component, the grid component captures my mousewheel scroll rather than the listbox. What I want to achieve is for the scroll function to remain with the listbox and only scroll the Grid when it/cell is clicked. If I set grid hittest to false it works fine but how do I go about detecting when my mouse is over the grid component to capture any mousedown events to reactivate the Grid for scrolling?

Here is the form I am using

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 736
  ClientWidth = 636
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 0
  object ListBox1: TListBox
    Align = Client
    Size.Width = 636.000000000000000000
    Size.Height = 736.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 1
    DisableFocusEffect = True
    DefaultItemStyles.ItemStyle = ''
    DefaultItemStyles.GroupHeaderStyle = ''
    DefaultItemStyles.GroupFooterStyle = ''
    Viewport.Width = 616.000000000000000000
    Viewport.Height = 732.000000000000000000
    object ListBoxItem1: TListBoxItem
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
    end
    object ListBoxItem2: TListBoxItem
      Position.Y = 65.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 1
    end
    object ListBoxItem3: TListBoxItem
      Position.Y = 130.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 2
    end
    object ListBoxItem4: TListBoxItem
      Position.Y = 195.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 3
    end
    object ListBoxItem5: TListBoxItem
      Position.Y = 260.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 500.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 4
      object Grid1: TGrid
        Align = Client
        CanFocus = True
        ClipChildren = True
        Size.Width = 616.000000000000000000
        Size.Height = 500.000000000000000000
        Size.PlatformDefault = False
        TabOrder = 40
        Viewport.Width = 596.000000000000000000
        Viewport.Height = 475.000000000000000000
        object Column1: TColumn
        end
        object Column2: TColumn
        end
      end
    end
    object ListBoxItem6: TListBoxItem
      Position.Y = 760.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 5
    end
    object ListBoxItem7: TListBoxItem
      Position.Y = 825.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 6
    end
    object ListBoxItem8: TListBoxItem
      Position.Y = 890.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 7
    end
    object ListBoxItem9: TListBoxItem
      Position.Y = 955.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 8
    end
    object ListBoxItem10: TListBoxItem
      Position.Y = 1020.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 9
    end
    object ListBoxItem11: TListBoxItem
      Position.Y = 1085.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 10
    end
    object ListBoxItem12: TListBoxItem
      Position.Y = 1150.000000000000000000
      Size.Width = 616.000000000000000000
      Size.Height = 65.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 11
    end
  end
end

CodePudding user response:

Set property Grid1.DisableMouseWheel := True in designer.

Then on Grid1Click set Grid1.DisableMouseWheel := False and

again on ListBox1Click set Grid1.DisableMouseWheel := True.

  •  Tags:  
  • Related