[Gambas-user] Web application - Reorder object into a WebContainer

Linus olivier.cruilles at yahoo.fr
Sat Feb 3 23:02:24 CET 2024


Hello,

I'm developing a new aWeb application in Gambas (gb.web.gui component used) as a simple WebForm.

Inside there is a WebContainer that I fill with few Objects like another WebForm including a WebPicture + few WebButtons.

During the insertion of the Objects into the WebContainer, they are ordered in the order they are created.
The objects (WebForm with the image) are displayed like Rows order or Column order.

Now I'm trying to re-organize the order of the Objects into the WebContainer in a way to change the place of each WebForm into the WebContainer and I'm not able to figure that.

Does someone as an idea to point me please ?

Example of code to fill the WebContainer with the objects:

Public Sub Create_Graph()

  Dim Graph1 As WebGraph
  Dim Graph2 As WebGraph
  Dim Graph3 As WebGraph
  Dim Graph4 As WebGraph
  Dim Graph5 As WebGraph
  Dim Graph6 As WebGraph

  Graph1 = New WebGraph(WebContainerGraph) As "GraphEvent"
  Graph1.GraphId = 1
  Graph1.SetTitre = "PARIS"
  Object.Attach(Graph1, WebMain, "GraphEvent")
  $TabObjectGraph.Add(Graph1)
  '
  Graph2 = New WebGraph(WebContainerGraph) As "GraphEvent"
  Graph2.GraphId = 2
  Graph2.SetTitre = "LONDON"
  Object.Attach(Graph2, WebMain, "GraphEvent")
  $TabObjectGraph.Add(Graph2)
  '
  Graph3 = New WebGraph(WebContainerGraph) As "GraphEvent"
  Graph3.GraphId = 3
  Graph3.SetTitre = "VANCOUVER"
  Object.Attach(Graph3, WebMain, "GraphEvent")
  $TabObjectGraph.Add(Graph3)
  '
  Graph4 = New WebGraph(WebContainerGraph) As "GraphEvent"
  Graph4.GraphId = 4
  Graph4.SetTitre = "HUSTON"
  Object.Attach(Graph4, WebMain, "GraphEvent")
  $TabObjectGraph.Add(Graph4)
  '
  Graph5 = New WebGraph(WebContainerGraph) As "GraphEvent"
  Graph5.GraphId = 5
  Graph5.SetTitre = "LOSANGELES"
  Object.Attach(Graph5, WebMain, "GraphEvent")
  $TabObjectGraph.Add(Graph5)
  '
  Graph6 = New WebGraph(WebContainerGraph) As "GraphEvent"
  Graph6.GraphId = 6
  Graph6.SetTitre = "MADRID"
  Object.Attach(Graph6, WebMain, "GraphEvent")
  $TabObjectGraph.Add(Graph6)

End

Public Sub ReOrder_Object(IdOfPictureObject as integer)

  Dim oGraphItem As Object
  Dim oGraphAdd As Object
  Dim oGraphTemp As Object
  Dim iNumGraph As Integer
  Dim SavGraphItem As Object[]
  Dim Index As Integer

  Index = 0

  '' Save the array of WebForm contained into the WebContainer before the 'move'
  SavGraphItem = WebContainerGraph.Children.Extract(0, WebContainerGraph.Children.Max)

  '' Search the Id of WebForm Object we want to move 
  For Each oGraphItem In SavGraphItem
    If oGraphItem.GraphId = IdOfPictureObject Then 
      iNumGraph = Index
      Break 
    End If

    Inc Index
  Next

  '' If the Id of the Object has been found and not the first one, we move it
  If iNumGraph > 0 Then  

    ' Move Object in the Array of Object
    SavGraphItem.Insert(SavGraphItem.Extract(Index), Index - 1)

    WebContainerGraph.DeleteChildren()

    For Each oGraphAdd In SavGraphItem   
      Try Object.Attach(oGraphAdd, WebContainerGraph, "GraphEvent")   ' <--- Fail because after 'WebContainerGraph.DeleteChildren()', all objects in 'SavGraphItem' are 'invalide'
    Next

  End If

End

Thank you

Olivier Cruilles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20240203/98f43748/attachment-0001.htm>


More information about the User mailing list