User Tools

Site Tools


k18:k18.12:start

18.12 ListContainer

The ListContainer class (gb.form) provides a modified container (ListBox) that can hold and display other components. These components can also be containers.

You will use the container component ListContainer above all if you want to display a lot of data with the same structure, which is read in anew each time the programme is started or which can change at programme runtime. The application purpose determines the selection of the components that are inserted into the ListContainer.

IDE Startbildschirm

Figure 18.12.1: Use of the ListContainer component (Gambas start screen (detail))

18.12.1 Properties

The following table describes the properties of the ListContainer component:

ListContainerData typeDefaultDescription
BorderBooleanFalseDetermines whether a border is displayed or returns this value.
CountInteger1Returns the number of components in the container.
CurrentControl-Determines which component is selected in the container or returns the component.
IndexInteger1Returns the index of the selected component in the container or specifies the index.

Table 18.12.1.1: ListContainer properties

18.12.2 Methods

The container component has five special methods, the description of which can be found in the next table:

ListContainerDescription
ClearAll components in the container are deleted.
EnsureVisibleEnsures that the current item in the container is visible.
LockPrevents a container refreshing until the method UnLock has been called.
UnLockUnlocks the container and refreshes it if necessary.
Select (hChild As Control)Selects the selected component in the container. Currently (Gambas 3.5.1) a ListContainer only works in single select mode.

Table 18.12.2.1: Methods ListContainer

18.12.3 Events

The container component has three special events: Activate, Click and Scroll.

  • Activate: The event is triggered when the user double-clicks on a component in the container.
  • Click: The event is triggered when the selected component in the container changes.
  • Scroll: The event is triggered when the user scrolls through the content in the container.

18.12.4 Adding Components to a ListContainer

You will not find an Add method - which you surely expected to find in the documentation - to add the components of your choice to a ListContainer. However, the following approach leads to the goal - be sure to try it out in a small project!

Public Sub btnExample_Click()
  Dim hCtrl As Control
  Dim bButton As Button
  Dim txbTextBox As TextBox
  Dim txtTextarea As TextArea
  Dim hForm As Form
 
  bButton = New Button(ListContainer2) As "B1"
  bButton.H = 24
  bButton.Text = "Button 1 oben"
  txbTextBox = New TextBox(ListContainer2) As "TB1"
  txbTextBox.H = 24
  txbTextBox.Text = "** TextBox **"
  hCtrl = New Panel(ListContainer2) As "P1"
  hCtrl.H = 32
  txtTextarea = New TextArea(ListContainer2) As "TA"
  txtTextarea.H = 80
  txtTextarea.Text = "Die ListContainer-Komponente besitzt ein Click-Ereignis."
  txtTextarea.Text &= gb.NewLine & "Es wird ausgelöst, wenn sich die Auswahl ändert."
  txtTextarea.Wrap = True
  bButton = New Button(ListContainer2) As "B2"
  bButton.H = 24
  bButton.Text = "Button 2 unten"
  hForm = New Form(ListContainer2) As "F1"
  hForm.H = 48
  hForm.Border = True
  hForm.Background = &HDFA08B
    bButton = New Button(hform) As "F1Button1"
    bButton.H = 24
    bButton.X = 8
    bButton.Y = 16
    bButton.W = 88
    bButton.Text = "Mitteilung"
  ListContainer2.Index = 3
 
End
 
Public Sub F1Button1_Click()
  Message.Info("Ich fühle mich unter-drückt!")
End

The TextBox and the TextArea are writable and also a click on the 2 buttons as well as on the F1Button1 button in the inserted form works.

18.12.5 RSS reader project

Information on RSS can be found at http://www.rssboard.org/rss-specification. In the foreground of the presented project RSS-Reader, however, is the use of the ListContainer component.

  • First, the data stream in XML format for a given RSS feed is loaded from the specified server and stored in a string.
  • Then the string is parsed. The mandatory channel elements title, description and link are read and (temporarily) stored.
  • Then (feed) forms (→ class FeedItem.Class) are created, to which only the two elements title and description are assigned as content in two selected components (TextArea). The inserted icon is the same for all (feed) forms.
  • Subsequently, the (feed) forms are added to a ListContainer.

A click on a (feed) form in the ListContainer selects the form, returns an index and launches the link matching this index in a WebView.

Hint:

In response to the author's enquiry in connection with this feed reader project for the online book, ARD wrote: In principle, you may use XML that we offer anywhere. However, images may … not be published anywhere, because some of them are agency images for which we only pay for our own platforms. Hence the image retouching in the following image:

Laufzeit

Figure 18.12.5.1: Project RSS reader - programme runtime

IDE

Figure 18.12.5.2: (Feed) form for the RSS reader project - development time.

Notes:

  • Of course, you can also define the (feed) form to be inserted completely in the source code, as you can read in the above source code excerpt in the section below. However, it is quicker and less error-prone with regard to the arrangement of the components on the form to use the class FeedItem.Class → Figure 18.12.5.2.
  • You should still develop the RSS reader project further, because it still lacks a few things in terms of error prevention and error handling, for example, as well as the ability to add new feeds.
  • You can read the extensive source code in the RSS-Reader project, which you can access in the download area.

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k18/k18.12/start.txt · Last modified: 07.10.2023 by emma

Page Tools