Page 6 of 6

Re: Simple PropertyGrid

Posted: Mon Jun 08, 2015 2:21 am
by ricardo
A way to open/close ALL sections of the original Danilo's code?

Re: Simple PropertyGrid

Posted: Sun Jun 21, 2015 11:13 am
by hjf
Hello Guimauve,

your download is down. Where can Idownload your last version ?

Regards
hjf

Re: Simple PropertyGrid

Posted: Sun Jun 21, 2015 11:54 am
by Danilo
ricardo wrote:A way to open/close ALL sections of the original Danilo's code?

Code: Select all

Procedure OpenAllSections(PropertyGridGadget)
    *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
    If *memory
        ForEach *memory\Items()
            *memory\Items()\Opened = #True
            SetGadgetState(*memory\Items()\SectionButtonGadget,ImageID(__GetPropertyGridImage(#True)))
            ForEach *memory\Items()\SubItems()
                HideGadget( *memory\Items()\SubItems()\DescriptionGadget , #False )
                HideGadget( *memory\Items()\SubItems()\ItemGadget        , #False )
            Next
        Next
        UpdatePropertyGrid(PropertyGridGadget)
    EndIf
EndProcedure

Procedure CloseAllSections(PropertyGridGadget)
    *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
    If *memory
        ForEach *memory\Items()
            *memory\Items()\Opened = #False
            SetGadgetState(*memory\Items()\SectionButtonGadget,ImageID(__GetPropertyGridImage(#False)))
            ForEach *memory\Items()\SubItems()
                HideGadget( *memory\Items()\SubItems()\DescriptionGadget , #True )
                HideGadget( *memory\Items()\SubItems()\ItemGadget        , #True )
            Next
        Next
        UpdatePropertyGrid(PropertyGridGadget)
    EndIf
EndProcedure

Re: Simple PropertyGrid

Posted: Sat Sep 05, 2015 2:08 am
by StarBootics
hjf wrote:Hello Guimauve,

your download is down. Where can Idownload your last version ?

Regards
hjf
This is the Module version of the Guimauve's code :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : PropertyGrid Gadget Module
; File Name : PropertyGrid Gadget Module.pb
; File version: 0.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 04-09-2015
; Last Update : 04-09-2015
; PureBasic code : V5.31
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Please note this code originally created by 
; Guimauve. The only credit I deserve is the 
; Modularization of the original code.
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule PropertyGrid
  
  CompilerSelect #PB_Compiler_OS
      
    CompilerCase #PB_OS_Windows
      #SECTION_FONT = "Arial"
      #DEFAULT_ITEM_HEIGHT = 20
      #SECTION_FONT_SIZE   = 10
      
    CompilerCase #PB_OS_Linux
      #SECTION_FONT = "Mint Spirit"
      #DEFAULT_ITEM_HEIGHT = 30
      #SECTION_FONT_SIZE   = 10
      
    CompilerCase #PB_OS_MacOS
      #SECTION_FONT = "Arial"
      #DEFAULT_ITEM_HEIGHT = 25
      #SECTION_FONT_SIZE   = 14
      
    CompilerDefault ; FUTURE
      #SECTION_FONT = "Arial"
      #DEFAULT_ITEM_HEIGHT = 20
      #SECTION_FONT_SIZE   = 12
      
  CompilerEndSelect
  
  Declare Gadget(PropertyGridID, x, y, Width, Height, FrontColor.l = -1, BackColor.l = -1, Flags = #PB_ScrollArea_Flat)
  Declare AddSection(PropertyGridID, SectionName.s, IsOpen.b = #True)
  Declare SetSectionName(PropertyGridID, SectionNo, SectionName.s)
  Declare.s GetSectionName(PropertyGridID, SectionNo)
  Declare CheckSectionClick(PropertyGridID)
  
  Declare SetSectionItemDescription(PropertyGridID, SectionNo, ItemNo, Description.s)
  Declare SetSectionItemContent(PropertyGridID, SectionNo, ItemNo, Content.s)
  Declare.s GetSectionItemContent(PropertyGridID, SectionNo, ItemNo)
  Declare SetSectionItemGadgetState(PropertyGridID, SectionNo, ItemNo, State)
  Declare GetSectionItemGadgetHandle(PropertyGridID, SectionNo, ItemNo)
  
  Declare GetSectionItemGadgetState(PropertyGridID, SectionNo, ItemNo)
  Declare GetSectionCount(PropertyGridID)
  Declare GetSectionItemCount(PropertyGridID, SectionNo)
  Declare AddStringGadget(PropertyGridID, SectionNo, Description.s = "", Content.s = "", Flags = 0, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
  Declare AddButtonGadget(PropertyGridID, SectionNo, Description.s = "", Content.s = "", Flags = 0, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
  
  Declare AddCheckBoxGadget(PropertyGridID, SectionNo, Description.s = "", Flags = 0)
  Declare AddOptionGadget(PropertyGridID, SectionNo, Description.s = "")
  Declare AddTextGadget(PropertyGridID, SectionNo, Description.s = "", Flags = 0)
  Declare AddComboBoxGadget(PropertyGridID, SectionNo, Description.s = "", Flags = 0, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
  Declare AddGadgetItems(PropertyGridID, SectionNo, ItemNo, Position, Text.s)
  
  Declare AddSpinGadget(PropertyGridID, SectionNo, Description.s = "", Minimum = 0, Maximum = 100, Flags = #PB_Spin_Numeric | #PB_Spin_ReadOnly, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
  Declare AddTrackBarGadget(PropertyGridID, SectionNo, Description.s = "", Minimum = 0, Maximum = 100, Flags = #PB_TrackBar_Ticks, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
  Declare AddProgressBarGadget(PropertyGridID, SectionNo, Description.s = "", Minimum = 0, Maximum = 100, Flags = #PB_ProgressBar_Smooth, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
  Declare AddListIconGadget(PropertyGridID, SectionNo, Description.s = "", Title.s = "", TitleWidth = 100, Flags = 0, P_ItemGadgetHeight = 100) 
  Declare DisableSectionGadgets(PropertyGridID, SectionNo, State)
  
  Declare ClearSectionGadgets(PropertyGridID, SectionNo)
  Declare ClearGadgets(PropertyGridID)
  Declare Free(PropertyGridID)
  
EndDeclareModule

Module PropertyGrid

  Structure SubItem
    
    DescriptionGadget.i
    ItemGadget.i
    ItemGadgetHeight.i
    
  EndStructure
  
  Structure Item
    
    SectionDescriptionGadget.i
    SectionButtonGadget.i
    IsSection.i
    Opened.i
    List SubItems.SubItem()
    
  EndStructure
  
  Structure PropertyGridData
    
    ItemHeight.i
    Font.i
    BackColor.l
    FrontColor.l
    List Items.Item()
    
  EndStructure
  
  Procedure Private_OpenClose_Image(IsOpen.b)
    
    Static OpenImage.i, CloseImage.i, OneShot.b
    
    If OneShot = #False
      
      OpenImage = CreateImage(#PB_Any, 11, 11, 32)
      
      If OpenImage And StartDrawing(ImageOutput(OpenImage))
        Box(0, 0, 11, 11, RGB($FF, $FF, $FF))
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(0, 0, 11, 11, RGB($00, $00, $00))
        LineXY(2, 5, 8, 5, RGB($00, $00, $00))
        StopDrawing()
      EndIf
      
      CloseImage = CreateImage(#PB_Any, 11, 11, 32)
      
      If CloseImage And StartDrawing(ImageOutput(CloseImage))
        Box(0,0,11,11,RGB($FF,$FF,$FF))
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(0,0,11,11,RGB($00,$00,$00))
        LineXY(2,5,8,5,RGB($00,$00,$00))
        LineXY(5,2,5,8,RGB($00,$00,$00))
        StopDrawing()
      EndIf
      
      OneShot = #True
      
    EndIf
    
    If IsOpen
      ProcedureReturn OpenImage
    Else
      ProcedureReturn CloseImage
    EndIf
    
  EndProcedure
  
  Procedure Private_Create_Item(*ItemA.Item, SectionName.s, Width, Height, FrontColor, BackColor, IsOpen.b, FontID)
    
    *ItemA\SectionDescriptionGadget = TextGadget(#PB_Any, 20, 0, width - 20, height, SectionName)
    *ItemA\SectionButtonGadget = ImageGadget(#PB_Any,0,0,0,0,ImageID(Private_OpenClose_Image(IsOpen)))
    
    *ItemA\IsSection = #True
    *ItemA\Opened = IsOpen
    
    SetGadgetFont(*ItemA\SectionDescriptionGadget, FontID(FontID))
    
    If BackColor <> -1
      SetGadgetColor(*ItemA\SectionDescriptionGadget, #PB_Gadget_BackColor, BackColor)
    EndIf
    
    If FrontColor <> -1
      SetGadgetColor(*ItemA\SectionDescriptionGadget, #PB_Gadget_FrontColor, FrontColor)
    EndIf
    
  EndProcedure
  
  Procedure Private_Relocate_SubItem(*SubItemA.SubItem, Index, Width, Height)
    
    CompilerSelect #PB_Compiler_OS
        
      CompilerCase #PB_OS_Windows 
        ResizeGadget(*SubItemA\DescriptionGadget, 20, Index,  width >> 1 - 40, height - 1)
        
        If IsGadget(*SubItemA\ItemGadget)
          ResizeGadget(*SubItemA\ItemGadget, width >> 1 - 19, Index, width >> 1 - 4, *SubItemA\ItemGadgetHeight - 1)
        EndIf
        
      CompilerCase #PB_OS_Linux
        ResizeGadget(*SubItemA\DescriptionGadget, 20, Index - 12, width >> 1 - 40, height - 1)
        
        If IsGadget(*SubItemA\ItemGadget)
          ResizeGadget(*SubItemA\ItemGadget, width >> 1 - 19, Index - 12, width >> 1 - 4, *SubItemA\ItemGadgetHeight - 1)
        EndIf
        
      CompilerCase #PB_OS_MacOS
        ResizeGadget(*SubItemA\DescriptionGadget, 20, Index, width >> 1 - 40, height - 1)
        
        If IsGadget(*SubItemA\ItemGadget)
          ResizeGadget(*SubItemA\ItemGadget, width >> 1 - 19, Index, width >> 1 - 4, *SubItemA\ItemGadgetHeight - 1)
        EndIf
        
    CompilerEndSelect
    
  EndProcedure
  
  Procedure Private_Relocate_Item(*ItemA.Item, Index, Width, Height)
    
    If *ItemA\IsSection = #True
      ResizeGadget(*ItemA\SectionDescriptionGadget, 20, Index, Width - 20, Height - 1)
      ResizeGadget(*ItemA\SectionButtonGadget, 4, Index + Height >> 1 - 12, 11, 11)
    Else
      ResizeGadget(*ItemA\SectionDescriptionGadget, 20, Index, Width >> 1 - 40, Height - 1)
      ResizeGadget(*ItemA\SectionButtonGadget, Width >> 1 - 19, Index, Width >> 1 - 4, Height - 1)
    EndIf
    
    Index + Height
    
    If *ItemA\Opened = #True
      
      ForEach *ItemA\SubItems()
        Private_Relocate_SubItem(*ItemA\SubItems(), Index, Width, Height)
        Index + *ItemA\SubItems()\ItemGadgetHeight
      Next
      
    EndIf
    
    ProcedureReturn Index
  EndProcedure
  
  Procedure Private_Update(PropertyGridID)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      Index = 0
      height = *PropertyGridDataA\ItemHeight
      width  = GadgetWidth(PropertyGridID)
      
      ForEach *PropertyGridDataA\Items()
        Index = Private_Relocate_Item( *PropertyGridDataA\Items(), Index, Width, Height)
      Next
      
      If GetGadgetAttribute(PropertyGridID, #PB_ScrollArea_InnerHeight) <> Index
        SetGadgetAttribute(PropertyGridID, #PB_ScrollArea_InnerHeight, Index)
      EndIf
      
      If GetGadgetAttribute(PropertyGridID, #PB_ScrollArea_InnerWidth) <> width - 20
        SetGadgetAttribute(PropertyGridID, #PB_ScrollArea_InnerWidth, width - 20)
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure Private_Hide_SubItem(*SubItemA.SubItem, IsOpen.b)
    
    HideGadget(*SubItemA\DescriptionGadget, 1 - IsOpen)
    
    If IsGadget(*SubItemA\ItemGadget)
      HideGadget(*SubItemA\ItemGadget, 1 - IsOpen)
    EndIf
    
  EndProcedure
  
  Procedure Private_Item_EventManagement(*ItemA.Item)
    
    If EventGadget() = *ItemA\SectionButtonGadget And EventType() = #PB_EventType_LeftClick
      
      *ItemA\Opened = *ItemA\Opened ! 1
      
      SetGadgetState(*ItemA\SectionButtonGadget, ImageID(Private_OpenClose_Image(*ItemA\Opened)))
      
      ForEach *ItemA\SubItems()
        Private_Hide_SubItem(*ItemA\SubItems(), *ItemA\Opened)
      Next
      
      SomethingHappen.b = #True
      
    EndIf
    
    ProcedureReturn SomethingHappen
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  
  Procedure Gadget(PropertyGridID, x, y, Width, Height, FrontColor.l = -1, BackColor.l = -1, Flags = #PB_ScrollArea_Flat)
    
    GadgetHandle = ScrollAreaGadget(PropertyGridID, x, y, Width, Height, Width - 20, 1, #DEFAULT_ITEM_HEIGHT, Flags)
      
      If GadgetHandle
        
        If PropertyGridID = #PB_Any
          PropertyGridID = GadgetHandle
        EndIf
        
        If FrontColor <> -1
          SetGadgetColor(PropertyGridID, #PB_Gadget_FrontColor, FrontColor)
        EndIf
        
        If BackColor <> -1
          SetGadgetColor(PropertyGridID, #PB_Gadget_BackColor, BackColor)
        EndIf
        
        *PropertyGridDataA.PropertyGridData = AllocateMemory(SizeOf(PropertyGridData))
        
        If *PropertyGridDataA = #Null
          FreeGadget(PropertyGridID)
          ProcedureReturn 0
        EndIf
        
        InitializeStructure(*PropertyGridDataA, PropertyGridData)
        
        
        *PropertyGridDataA\ItemHeight = #DEFAULT_ITEM_HEIGHT
        *PropertyGridDataA\Font = LoadFont(#PB_Any, #SECTION_FONT, #SECTION_FONT_SIZE, #PB_Font_Bold)
        *PropertyGridDataA\BackColor = BackColor
        *PropertyGridDataA\FrontColor = FrontColor
        
        SetGadgetData(PropertyGridID, *PropertyGridDataA)
        
      CloseGadgetList()
      
    EndIf
    
    ProcedureReturn PropertyGridID
  EndProcedure
  
  Procedure AddSection(PropertyGridID, SectionName.s, IsOpen.b = #True)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      LastElement(*PropertyGridDataA\Items())
      
      If AddElement(*PropertyGridDataA\Items())
        
        InitializeStructure(*PropertyGridDataA\Items(), Item)
        
        OpenGadgetList(PropertyGridID)
          
          Private_Create_Item(*PropertyGridDataA\Items(), SectionName, GadgetWidth(PropertyGridID), *PropertyGridDataA\ItemHeight, *PropertyGridDataA\FrontColor, *PropertyGridDataA\BackColor, IsOpen, *PropertyGridDataA\Font)
          
        CloseGadgetList()
        
        Private_Update(PropertyGridID)
        
        ProcedureReturn #True
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure SetSectionName(PropertyGridID, SectionNo, SectionName.s)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          SetGadgetText(*PropertyGridDataA\Items()\SectionDescriptionGadget, SectionName)
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
  
  Procedure.s GetSectionName(PropertyGridID, SectionNo)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          ProcedureReturn GetGadgetText(*PropertyGridDataA\Items()\SectionDescriptionGadget)
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure 
  
  Procedure CheckSectionClick(PropertyGridID)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      ForEach *PropertyGridDataA\Items()
        If Private_Item_EventManagement(*PropertyGridDataA\Items())
          Private_Update(PropertyGridID)
          Break
        EndIf
      Next
      
      Private_Update(PropertyGridID)
      
    EndIf
    
  EndProcedure
  
  Procedure SetSectionItemDescription(PropertyGridID, SectionNo, ItemNo, Description.s)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          If ItemNo >= 0 And ItemNo <= ListSize(*PropertyGridDataA\Items()\SubItems()) - 1
            
            If SelectElement(*PropertyGridDataA\Items()\SubItems(), ItemNo)
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                SetGadgetText(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget, Description)
              EndIf
              
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
  
  Procedure SetSectionItemContent(PropertyGridID, SectionNo, ItemNo, Content.s)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          If ItemNo >= 0 And ItemNo <= ListSize(*PropertyGridDataA\Items()\SubItems()) - 1
            
            If SelectElement(*PropertyGridDataA\Items()\SubItems(), ItemNo)
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                SetGadgetText(*PropertyGridDataA\Items()\SubItems()\ItemGadget, Content)
              EndIf
              
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf 

    EndIf
    
  EndProcedure
  
  Procedure.s GetSectionItemContent(PropertyGridID, SectionNo, ItemNo)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          If ItemNo >= 0 And ItemNo <= ListSize(*PropertyGridDataA\Items()\SubItems()) - 1
            
            If SelectElement(*PropertyGridDataA\Items()\SubItems(), ItemNo)
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                ProcedureReturn GetGadgetText(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
              EndIf
              
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf 
      
    EndIf
    
  EndProcedure

  Procedure SetSectionItemGadgetState(PropertyGridID, SectionNo, ItemNo, State)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null

      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          If ItemNo >= 0 And ItemNo <= ListSize(*PropertyGridDataA\Items()\SubItems()) - 1
            
            If SelectElement(*PropertyGridDataA\Items()\SubItems(), ItemNo)
              
              If *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
                
                If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                  SetGadgetState(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget, State)
                  ProcedureReturn 1 
                Else
                  ProcedureReturn -1
                EndIf
                
              Else
                
                If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                  SetGadgetState(*PropertyGridDataA\Items()\SubItems()\ItemGadget, State)
                  ProcedureReturn 1 
                Else
                  ProcedureReturn -1
                EndIf
                
              EndIf
              
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure GetSectionItemGadgetHandle(PropertyGridID, SectionNo, ItemNo)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          If ItemNo >= 0 And ItemNo <= ListSize(*PropertyGridDataA\Items()\SubItems()) - 1
            
            If SelectElement(*PropertyGridDataA\Items()\SubItems(), ItemNo)
              
              If *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
                
                If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                  ProcedureReturn *PropertyGridDataA\Items()\SubItems()\DescriptionGadget
                Else
                  ProcedureReturn -1
                EndIf
                
              Else
                
                If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                  ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
                Else
                  ProcedureReturn -1
                EndIf
                
              EndIf
              
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure GetSectionItemGadgetState(PropertyGridID, SectionNo, ItemNo)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          If ItemNo >= 0 And ItemNo <= ListSize(*PropertyGridDataA\Items()\SubItems()) - 1
            
            If SelectElement(*PropertyGridDataA\Items()\SubItems(), ItemNo)
              
              If *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
                
                If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                  ProcedureReturn GetGadgetState(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                Else
                  ProcedureReturn -1
                EndIf
                
              Else
                
                If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                  ProcedureReturn GetGadgetState(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                Else
                  ProcedureReturn -1
                EndIf
                
              EndIf
              
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf
      
    EndIf
    
  EndProcedure
  
  Procedure GetSectionCount(PropertyGridID)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    SectionCount.l = -1
    
    If *PropertyGridDataA <> #Null
      SectionCount = *PropertyGridDataA\Items()
    EndIf
    
    ProcedureReturn SectionCount
  EndProcedure
  
  Procedure GetSectionItemCount(PropertyGridID, SectionNo)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    SectionItemCount.l = -1
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          SectionItemCount = ListSize(*PropertyGridDataA\Items()\SubItems())
        EndIf 
        
      EndIf
      
    EndIf
    
    ProcedureReturn SectionItemCount
  EndProcedure

  Procedure AddStringGadget(PropertyGridID, SectionNo, Description.s = "", Content.s = "", Flags = 0, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Content, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
            
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
   
  Procedure AddButtonGadget(PropertyGridID, SectionNo, Description.s = "", Content.s = "", Flags = 0, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = ButtonGadget(#PB_Any, 0, 0, 0, 0, Content, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
            
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
  
  Procedure AddCheckBoxGadget(PropertyGridID, SectionNo, Description.s = "", Flags = 0)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = CheckBoxGadget(#PB_Any, 0, 0, 0, 0, Description, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\DescriptionGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
  
  Procedure AddOptionGadget(PropertyGridID, SectionNo, Description.s = "")
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = OptionGadget(#PB_Any, 0, 0, 0, 0, Description)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\DescriptionGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure 

  Procedure AddTextGadget(PropertyGridID, SectionNo, Description.s = "", Flags = 0)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = TextGadget(#PB_Any, 0, 0, 0, 0, Description, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\DescriptionGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure

  Procedure AddComboBoxGadget(PropertyGridID, SectionNo, Description.s = "", Flags = 0, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = ComboBoxGadget(#PB_Any, 0, 0, 0, 0, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
            
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
  
  Procedure AddGadgetItems(PropertyGridID, SectionNo, ItemNo, Position, Text.s)
    
    GadgetHandle = GetSectionItemGadgetHandle(PropertyGridID, SectionNo, ItemNo)
    
    If IsGadget(GadgetHandle)
      AddGadgetItem(GadgetHandle, Position, Text)
    EndIf
    
  EndProcedure

  Procedure AddSpinGadget(PropertyGridID, SectionNo, Description.s = "", Minimum = 0, Maximum = 100, Flags = #PB_Spin_Numeric | #PB_Spin_ReadOnly, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = SpinGadget(#PB_Any, 0, 0, 0, 0, Minimum, Maximum, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
  
  Procedure AddTrackBarGadget(PropertyGridID, SectionNo, Description.s = "", Minimum = 0, Maximum = 100, Flags = #PB_TrackBar_Ticks, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = TrackBarGadget(#PB_Any, 0, 0, 0, 0, Minimum, Maximum, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure

  Procedure AddProgressBarGadget(PropertyGridID, SectionNo, Description.s = "", Minimum = 0, Maximum = 100, Flags = #PB_ProgressBar_Smooth, P_ItemGadgetHeight = #DEFAULT_ITEM_HEIGHT)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = ProgressBarGadget(#PB_Any, 0, 0, 0, 0, Minimum, Maximum, Flags)
            *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure
    
  Procedure AddListIconGadget(PropertyGridID, SectionNo, Description.s = "", Title.s = "", TitleWidth = 100, Flags = 0, P_ItemGadgetHeight = 100) 
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID) 
    
    If *PropertyGridDataA <> #Null 
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          AddElement(*PropertyGridDataA\Items()\SubItems())
          
          OpenGadgetList(PropertyGridID)
            
            If Description <> ""
              *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)
              *PropertyGridDataA\Items()\SubItems()\ItemGadget = ListIconGadget(#PB_Any, 0, 0, 0, 0, Title, TitleWidth, Flags)
              *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
            Else
              *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = ListIconGadget(#PB_Any, 0, 0, 0, 0, Title, TitleWidth, Flags)
              *PropertyGridDataA\Items()\SubItems()\ItemGadget = -1
              *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = P_ItemGadgetHeight
            EndIf
            
          CloseGadgetList()
          
          Private_Update(PropertyGridID)
          
          If Description <> ""
            ProcedureReturn *PropertyGridDataA\Items()\SubItems()\ItemGadget
          Else
            ProcedureReturn *PropertyGridDataA\Items()\SubItems()\DescriptionGadget
          EndIf
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure 
  
  Procedure DisableSectionGadgets(PropertyGridID, SectionNo, State)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          OpenGadgetList(PropertyGridID)
            
            ForEach *PropertyGridDataA\Items()\SubItems()
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                DisableGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget, State)
              EndIf
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                DisableGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget, State)
              EndIf

            Next
            
          CloseGadgetList()
          
        EndIf
        
      EndIf    
      
    EndIf
    
  EndProcedure

  Procedure ClearSectionGadgets(PropertyGridID, SectionNo)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      If SectionNo >= 0 And SectionNo <= ListSize(*PropertyGridDataA\Items()) - 1
        
        If SelectElement(*PropertyGridDataA\Items(), SectionNo)
          
          OpenGadgetList(PropertyGridID)
            
            ForEach *PropertyGridDataA\Items()\SubItems()
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                FreeGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
                *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = 0
              EndIf
              
              If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                FreeGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
                *PropertyGridDataA\Items()\SubItems()\ItemGadget = 0
              EndIf
              
              *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = 0
              
            Next
            
            ClearList(*PropertyGridDataA\Items()\SubItems())
            
          CloseGadgetList()
          
        EndIf
        
      EndIf    
      
      Private_Update(PropertyGridID)
      
    EndIf
    
  EndProcedure
  
  Procedure ClearGadgets(PropertyGridID)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      ForEach *PropertyGridDataA\Items()
        
        If IsGadget(*PropertyGridDataA\Items()\SectionDescriptionGadget)
          FreeGadget(*PropertyGridDataA\Items()\SectionDescriptionGadget)
          *PropertyGridDataA\Items()\SectionDescriptionGadget = 0
        EndIf
        
        If IsGadget(*PropertyGridDataA\Items()\SectionButtonGadget)
          FreeGadget(*PropertyGridDataA\Items()\SectionButtonGadget)
          *PropertyGridDataA\Items()\SectionButtonGadget = 0
        EndIf
        
        *PropertyGridDataA\Items()\IsSection = 0
        *PropertyGridDataA\Items()\Opened = 0
        
        ForEach *PropertyGridDataA\Items()\SubItems()
          
          If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
            FreeGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = 0
          EndIf
          
          If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
            FreeGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = 0
          EndIf
          
          *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = 0
          
        Next
        
        ClearList(*PropertyGridDataA\Items()\SubItems())
        
      Next      
      
      ClearList(*PropertyGridDataA\Items())
      InitializeStructure(*PropertyGridDataA, PropertyGridData)
      
    EndIf
    
  EndProcedure
  
  Procedure Free(PropertyGridID)
    
    *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
    
    If *PropertyGridDataA <> #Null
      
      *PropertyGridDataA\ItemHeight = 0
      
      If IsFont(*PropertyGridDataA\Font)
        FreeFont(*PropertyGridDataA\Font)
        *PropertyGridDataA\Font = 0
      EndIf
      
      *PropertyGridDataA\BackColor = 0
      *PropertyGridDataA\FrontColor = 0
      
      ForEach *PropertyGridDataA\Items()
        
        If IsGadget(*PropertyGridDataA\Items()\SectionDescriptionGadget)
          FreeGadget(*PropertyGridDataA\Items()\SectionDescriptionGadget)
          *PropertyGridDataA\Items()\SectionDescriptionGadget = 0
        EndIf
        
        If IsGadget(*PropertyGridDataA\Items()\SectionButtonGadget)
          FreeGadget(*PropertyGridDataA\Items()\SectionButtonGadget)
          *PropertyGridDataA\Items()\SectionButtonGadget = 0
        EndIf
        
        *PropertyGridDataA\Items()\IsSection = 0
        *PropertyGridDataA\Items()\Opened = 0
        
        ForEach *PropertyGridDataA\Items()\SubItems()
          
          If IsGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
            FreeGadget(*PropertyGridDataA\Items()\SubItems()\DescriptionGadget)
            *PropertyGridDataA\Items()\SubItems()\DescriptionGadget = 0
          EndIf
          
          If IsGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
            FreeGadget(*PropertyGridDataA\Items()\SubItems()\ItemGadget)
            *PropertyGridDataA\Items()\SubItems()\ItemGadget = 0
          EndIf
          
          *PropertyGridDataA\Items()\SubItems()\ItemGadgetHeight = 0
          
        Next
        
        FreeList(*PropertyGridDataA\Items()\SubItems())
        
      Next      
      
      FreeList(*PropertyGridDataA\Items())
      ClearStructure(*PropertyGridDataA, PropertyGridData)
      FreeMemory(*PropertyGridDataA)
      FreeGadget(PropertyGridID)
      
    EndIf
 
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration 
    
    #PropertyGrid 
    #Btn_Clear_Section 
    
  EndEnumeration 
  
  If OpenWindow(0,0,0,800,600,"PropertyGrid",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
    
    ;HideWindow(0, #True) 
    
    PropertyGrid::Gadget(#PropertyGrid, 5, 5, 390, 500)
    
    ButtonGadget(#Btn_Clear_Section, 5, 510,150,30, "Clear Section 2") 
    
    
    For SectionID = 0 To 5 
      
      PropertyGrid::AddSection(#PropertyGrid, "Section 0" + Str(SectionID)) 
      PropertyGrid::AddCheckBoxGadget(#PropertyGrid, SectionID, "Is Visible") 
      PropertyGrid::AddStringGadget(#PropertyGrid, SectionID, "String", "Enter a text here !") 
      PropertyGrid::AddComboBoxGadget(#PropertyGrid, SectionID, "ComboBox") 
      PropertyGrid::AddButtonGadget(#PropertyGrid, SectionID, "Button", "Button 0" + Str(SectionID)) 
      PropertyGrid::AddSpinGadget(#PropertyGrid, SectionID, "SpinGadget", 0, 15) 
      PropertyGrid::AddTrackBarGadget(#PropertyGrid, SectionID, "TrackBar") 
      PropertyGrid::AddProgressBarGadget(#PropertyGrid, SectionID, "ProgressBar") 
      PropertyGrid::AddListIconGadget(#PropertyGrid, SectionID, "ListIcon", "Column 1")
      
      PropertyGrid::SetSectionItemGadgetState(#PropertyGrid, SectionID, 0, 1) 
      
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 2, 0, "ComboBox Item 0") 
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 2, 1, "ComboBox Item 1") 
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 2, 2, "ComboBox Item 2") 
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 2, 3, "ComboBox Item 3") 
      
      PropertyGrid::SetSectionItemGadgetState(#PropertyGrid, SectionID, 5, Random(90) + 5) 
      PropertyGrid::SetSectionItemGadgetState(#PropertyGrid, SectionID, 6, Random(90) + 5) 
      
      ; Add items to the listicon (GadgetID = 7):
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 7, 0, "ListIcon Item 0")
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 7, 1, "ListIcon Item 1")
      PropertyGrid::AddGadgetItems(#PropertyGrid, SectionID, 7, 2, "ListIcon Item 2")
      
    Next 
    
    HideWindow(0, #False) 
    
    Repeat 
      
      EventID = WaitWindowEvent() 
      
      Select EventID 
          
        Case #PB_Event_Menu 
          
          Select EventMenu() 
              
          EndSelect 
          
        Case #PB_Event_Gadget 
          
          Select EventGadget() 
              
            Case #PropertyGrid 
              
            Case #Btn_Clear_Section 
              PropertyGrid::ClearSectionGadgets(#PropertyGrid, 2) 
              
            Case PropertyGrid::GetSectionItemGadgetHandle(#PropertyGrid, 0, 0) 
              If PropertyGrid::GetSectionItemGadgetState(#PropertyGrid, 0, 0) 
                Debug "CheckBox Section 0 Item 1 (Is Visible)" 
              Else 
                Debug "CheckBox Section 0 Item 1 (Is not visible)" 
              EndIf 
              
            Default 
              PropertyGrid::CheckSectionClick(#PropertyGrid) 
              
          EndSelect 
          
      EndSelect 
      
    Until EventID = #PB_Event_CloseWindow 
    
    PropertyGrid::Free(#PropertyGrid) 
    
  EndIf 
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
I hope this can help you.

Best regards
StarBootics

Re: Simple PropertyGrid

Posted: Sat Sep 05, 2015 3:19 am
by electrochrisso
This is the Module version of the Guimauve's code :
Thanks for sharing StarBootics :) , Looks like you have been going a little Module crazy lately :lol:

Re: Simple PropertyGrid

Posted: Sat Sep 05, 2015 8:50 am
by hjf
Hello StarBootics,

Thankyou for the Modul!

Regards
hjf

Re: Simple PropertyGrid

Posted: Sun Sep 13, 2015 6:21 am
by StarBootics
electrochrisso wrote:Looks like you have been going a little Module crazy lately :lol:
Actually, I'm re-writing all of my programs using only Module, more crazy than you think !

Re: Simple PropertyGrid

Posted: Tue Sep 06, 2016 5:31 pm
by Kwai chang caine
I use the nice PropertyGadget of DANILO but i have a strange behaviour :|
When i click on the combo, the dropdown list is more height than the number of items (white field) :shock:
When i clic a second time, the dropdownlist is exactely height than the number of items :shock:

After i clic on the textgadget beside and give to it the focus
And when i click a new time on the combo, the dropdown list is more height than the number of items (white field) like at the beginning :shock:

I have searched why...and no found the reason
Perhaps someione have an idea ...

This the code with just the combogadget, but the same problem is in the full code of DANILO

Code: Select all

;
; Simple PropertyGrid
;
; by Danilo, May 2012, PureBasic 4.60
;
#PropertyGrid_SectionFont     = "Arial"
#PropertyGrid_DefaultItemHeight = 20
#PropertyGrid_SectionFontSize   = 10

Structure PropertyGridGadgetSubItem
 DescriptionGadget.i
 ItemGadget.i
EndStructure

Structure PropertyGridItem
 SectionDescriptionGadget.i
 SectionButtonGadget.i
 IsSection.i
 Opened.i
 List SubItems.PropertyGridGadgetSubItem()
EndStructure

Structure PropertyGridData
 ItemHeight.i
 Font.i
 backColor.q
 frontColor.q
 List Items.PropertyGridItem()
EndStructure

Procedure __GetPropertyGridImage(open.i)
 Static openImage.i, closeImage.i
 
 If Not openImage
  openImage = CreateImage(#PB_Any,11,11,24)
  If openImage And StartDrawing( ImageOutput(openImage) )
   Box(0,0,11,11,RGB($FF,$FF,$FF))
   DrawingMode(#PB_2DDrawing_Outlined)
   Box(0,0,11,11,RGB($00,$00,$00))
   LineXY(2,5,8,5,RGB($00,$00,$00))
   StopDrawing()
  EndIf
 EndIf
 If Not closeImage
  closeImage = CreateImage(#PB_Any,11,11,24)
  If closeImage And StartDrawing( ImageOutput(closeImage) )
   Box(0,0,11,11,RGB($FF,$FF,$FF))
   DrawingMode(#PB_2DDrawing_Outlined)
   Box(0,0,11,11,RGB($00,$00,$00))
   LineXY(2,5,8,5,RGB($00,$00,$00))
   LineXY(5,2,5,8,RGB($00,$00,$00))
   StopDrawing()
  EndIf
 EndIf
 
 
 If open
  ProcedureReturn openImage
 Else
  ProcedureReturn closeImage
 EndIf
EndProcedure

Procedure UpdatePropertyGrid(PropertyGridGadget)
 *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
 If *memory
  i = 0
  height = *memory\ItemHeight
  width  = GadgetWidth(PropertyGridGadget)
  ForEach *memory\Items()
   If *memory\Items()\IsSection
    ResizeGadget( *memory\Items()\SectionDescriptionGadget,20,i,width-20,height-1)
    ResizeGadget( *memory\Items()\SectionButtonGadget     , 4,i+height*0.5-6,11,11)
   Else
    ResizeGadget( *memory\Items()\SectionDescriptionGadget,20,i,width*0.5-40,height-1)
    ResizeGadget( *memory\Items()\SectionButtonGadget     ,width*0.5-19,i,width*0.5-4,height-1)
   EndIf
   i + height
   If *memory\Items()\Opened
    ForEach *memory\Items()\SubItems()
     ResizeGadget( *memory\Items()\SubItems()\DescriptionGadget,20,i,width*0.5-40,height-1)
     ResizeGadget( *memory\Items()\SubItems()\ItemGadget       ,width*0.5-19,i,width*0.5-4,height-1)
     i + height
    Next
   EndIf
  Next
  If GetGadgetAttribute(PropertyGridGadget,#PB_ScrollArea_InnerHeight) <> i
   SetGadgetAttribute(PropertyGridGadget,#PB_ScrollArea_InnerHeight,i)
  EndIf
  If GetGadgetAttribute(PropertyGridGadget,#PB_ScrollArea_InnerWidth) <> width-20
   SetGadgetAttribute(PropertyGridGadget,#PB_ScrollArea_InnerWidth,width-20)
  EndIf
  
 EndIf
EndProcedure

Procedure __SetSection(PropertyGridGadget,section)
 *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
 If *memory
  If section = 0
   LastElement( *memory\Items() )
   OpenGadgetList(PropertyGridGadget)
   ProcedureReturn #True
  EndIf
  ForEach *memory\Items()
   If *memory\Items()\SectionButtonGadget = section
    OpenGadgetList(PropertyGridGadget)
    ProcedureReturn #True
   EndIf
  Next
 EndIf
EndProcedure

Procedure __AddSectionItem(PropertyGridGadget,section,Description.s,Gadget.i)
 *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
 If *memory
  
  descGadget = StringGadget(#PB_Any,0,0,0,0,Description,#PB_String_ReadOnly)
  ;descGadget = TextGadget(#PB_Any,0,0,0,0,Description);,#PB_Text_Border)
  ;DisableGadget( descGadget, 1 )
  
  If section = 0
   If AddElement( *memory\Items() )
    *memory\Items()\IsSection = 0
    *memory\Items()\SectionButtonGadget      = Gadget
    *memory\Items()\SectionDescriptionGadget = descGadget
    CloseGadgetList()
    UpdatePropertyGrid(PropertyGridGadget)
    ProcedureReturn #True
   EndIf
  Else
   LastElement( *memory\Items()\SubItems() )
   If AddElement( *memory\Items()\SubItems() )
    *memory\Items()\SubItems()\DescriptionGadget = descGadget
    *memory\Items()\SubItems()\ItemGadget        = Gadget
    CloseGadgetList()
    If *memory\Items()\Opened
     UpdatePropertyGrid(PropertyGridGadget)
    Else
     HideGadget(*memory\Items()\SubItems()\DescriptionGadget,1)
     HideGadget(*memory\Items()\SubItems()\ItemGadget       ,1)
    EndIf
    ProcedureReturn #True
   EndIf
  EndIf
 EndIf
 FreeGadget(Gadget)
EndProcedure

Procedure PropertyGridGadget(gadgetNr,x,y,width,height,backColor.q=-1,frontColor.q=-1,flags=#PB_ScrollArea_Single)
 gadget = ScrollAreaGadget(gadgetNr,x,y,width,height,width-20,1,#PropertyGrid_DefaultItemHeight,flags)
 If gadget
  If gadgetNr = #PB_Any : gadgetNr = gadget : EndIf
  If backColor <> -1
   SetGadgetColor(gadgetNr,#PB_Gadget_BackColor,backColor)
  EndIf
  If frontColor <> -1
   SetGadgetColor(gadgetNr,#PB_Gadget_FrontColor,frontColor)
  EndIf
  *memory.PropertyGridData = AllocateMemory( SizeOf(PropertyGridData) )
  If Not *memory
   FreeGadget(gadgetNr)
   ProcedureReturn 0
  EndIf
  InitializeStructure(*memory,PropertyGridData)
  *memory\ItemHeight = #PropertyGrid_DefaultItemHeight
  *memory\Font       = LoadFont(#PB_Any,#PropertyGrid_SectionFont,#PropertyGrid_SectionFontSize,#PB_Font_Bold)
  *memory\backColor  = backColor
  *memory\frontColor = frontColor
  SetGadgetData(gadgetNr,*memory)
  CloseGadgetList()
 EndIf
 ProcedureReturn gadgetNr
EndProcedure

Procedure AddSection(PropertyGridGadget,sectionName.s,open.i=1)
 *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
 If *memory
  LastElement( *memory\Items() )
  If AddElement( *memory\Items() )
   OpenGadgetList(PropertyGridGadget)
   width  = GadgetWidth(PropertyGridGadget)
   height = *memory\ItemHeight
   gadget = TextGadget(#PB_Any,20,0,width-20,height,sectionName)
   *memory\Items()\SectionDescriptionGadget = gadget
   *memory\Items()\SectionButtonGadget      = ImageGadget(#PB_Any,0,0,0,0,ImageID(__GetPropertyGridImage(open)))
   *memory\Items()\Opened    = open
   *memory\Items()\IsSection = 1
   SetGadgetFont(gadget,FontID(*memory\Font))
   If *memory\backColor <> -1
    SetGadgetColor(gadget,#PB_Gadget_BackColor,*memory\backColor)
   EndIf
   If *memory\frontColor <> -1
    SetGadgetColor(gadget,#PB_Gadget_FrontColor,*memory\frontColor)
   EndIf
   CloseGadgetList()
   UpdatePropertyGrid(PropertyGridGadget)
   ProcedureReturn *memory\Items()\SectionButtonGadget
  EndIf
 EndIf
EndProcedure

Procedure CheckPropertyGridSectionClick(PropertyGridGadget,EventGadget,EventType)
 *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
 If *memory
  ForEach *memory\Items()
   If EventGadget = *memory\Items()\SectionButtonGadget And EventType = #PB_EventType_LeftClick
    *memory\Items()\Opened ! 1
    open = *memory\Items()\Opened
    SetGadgetState(*memory\Items()\SectionButtonGadget,ImageID(__GetPropertyGridImage(open)))
    ForEach *memory\Items()\SubItems()
     HideGadget( *memory\Items()\SubItems()\DescriptionGadget , 1-open )
     HideGadget( *memory\Items()\SubItems()\ItemGadget        , 1-open )
    Next
    UpdatePropertyGrid(PropertyGridGadget)
    Break
   EndIf
  Next
  UpdatePropertyGrid(PropertyGridGadget)
 EndIf
EndProcedure

;---[ PropertyGrid Gadgets ]---

Procedure AddStringGadget(PropertyGridGadget,section,Description.s,Content.s,flags=0)
 If __SetSection(PropertyGridGadget,section)
  gadget = StringGadget(#PB_Any,0,0,0,0,Content,flags)
  If __AddSectionItem(PropertyGridGadget,section,Description,gadget)
   ProcedureReturn gadget
  EndIf
 EndIf
EndProcedure

Procedure AddComboBoxGadget(PropertyGridGadget,section,Description.s,flags=0)
 If __SetSection(PropertyGridGadget,section)
  gadget = ComboBoxGadget(#PB_Any,0,0,0,0,flags)
  If __AddSectionItem(PropertyGridGadget,section,Description,gadget)
   ProcedureReturn gadget
  EndIf
 EndIf
EndProcedure

OpenWindow(0,0,0,400,600,"PropertyGrid",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)

prop = PropertyGridGadget(#PB_Any,10,10,300,580);,RGB($80,$80,$80),RGB($00,$00,$00))

section1 = AddSection(prop,"Section 1")

combo1 = AddComboBoxGadget(prop,section1,"Combobox 1", #PB_ComboBox_Editable)
For i = 1 To 10 : AddGadgetItem(combo1,-1,"Item "+Str(i)) : Next

While WindowEvent():Wend
HideWindow(0,0)

Repeat
 Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
   Break
  Case #PB_Event_Gadget
   EventGadget = EventGadget()
   EventType   = EventType()
   Select EventGadget
    Case btn1
     MessageRequester("INFO","Button pressed")
    Default
     ; check for PropertyGrid Events (section opened/closed)
     CheckPropertyGridSectionClick(prop ,EventGadget,EventType)
   EndSelect
 EndSelect
ForEver

Re: Simple PropertyGrid

Posted: Tue Sep 06, 2016 10:34 pm
by VB6_to_PBx
I use the nice PropertyGadget of DANILO but i have a strange behaviour :|
When i click on the combo, the dropdown list is more height than the number of items (white field) :shock:
When i clic a second time, the dropdownlist is exactely height than the number of items :shock:

After i clic on the textgadget beside and give to it the focus
And when i click a new time on the combo, the dropdown list is more height than the number of items (white field) like at the beginning :shock:

I have searched why...and no found the reason
Perhaps someione have an idea ...
it works perfect with PureBasic 5.31 32-Bit on my Win7-64bit Computer
i cannot make it do what you are getting ??

Re: Simple PropertyGrid

Posted: Wed Sep 07, 2016 8:23 am
by Kwai chang caine
Thanks VB6_to_PBx for have spent time to try this code 8)

It's strange, i have try another time but this time with v5.20 LTS and it's exactely the same behaviour :shock:
I have always the same effect

With line 249 Combo Editable (W7 x86 v5.20 and 5.40)

Code: Select all

combo1 = AddComboBoxGadget(prop,section1,"Combobox 1", #PB_ComboBox_Editable)
Image


With line 249 Combo not editable (W7 x86 v5.20 and 5.40)

Code: Select all

combo1 = AddComboBoxGadget(prop,section1,"Combobox 1")
Image

Re: Simple PropertyGrid

Posted: Mon Jun 19, 2017 11:18 pm
by Andre
I just don't see the right direction, how it can be done with the existing include...

I'm successfully using Guimauve's include in my project, which is now already converted from static handmade GUI's into resizeable dialogs (using the strong DynamicDialogs include by PureLust) and the PropertyGridGadget is just added after the dialog creation (inside a ContainerGadget) :mrgreen:

But currently there two things left:

1) How can I resize the PropertyGridGadget (ScrollArea) and its included gadgets, when a dialog resize was done. For example the PropertyGridGadget should get a greater width too, according to resized dialog?

2) Gadgets inside the PropertyGadgetGadget (used by me are the section title and listicons) are a bit too width, if the PropertyGridGadget gets a scrollbar on the right because of the contained gadgets. Then for example the scrollbar of a listicon is partly behind the scrollbar of the ScrollArea (PropertyGridGadget).

Any suggestions? Thank you :D

Re: Simple PropertyGrid

Posted: Mon Aug 28, 2017 10:10 am
by [blendman]
Hi

I have tried to add an imagegadget, but it doesn't work with the imageID, if the image width/height is bigger than the imagegadget() width/height, we can see the image under the image gadget.

Code: Select all

Procedure AddImageGadget(PropertyGridGadget,section,Description.s,imageId,flags=0)
  
  If __SetSection(PropertyGridGadget,section)
    *memory.PropertyGridData = GetGadgetData(PropertyGridGadget)
    If *memory
      width  = GadgetWidth(PropertyGridGadget)*0.5 - 4 
      height = *memory\ItemHeight
      ResizeImage(imageId,width,height - 1)
      gadget = ImageGadget(#PB_Any,0,0,width,height,ImageID(imageId))
      If __AddSectionItem(PropertyGridGadget,section,Description,gadget)
        ProcedureReturn gadget
      EndIf
    EndIf
  EndIf
  
EndProcedure
Any idea to fixe that ?

Thanks.

Edit :
ok fixed
I have changed the procedure