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.
Figure 18.12.1: Use of the ListContainer component (Gambas start screen (detail))
The following table describes the properties of the ListContainer component:
ListContainer | Data type | Default | Description |
---|---|---|---|
Border | Boolean | False | Determines whether a border is displayed or returns this value. |
Count | Integer | 1 | Returns the number of components in the container. |
Current | Control | - | Determines which component is selected in the container or returns the component. |
Index | Integer | 1 | Returns the index of the selected component in the container or specifies the index. |
Table 18.12.1.1: ListContainer properties
The container component has five special methods, the description of which can be found in the next table:
ListContainer | Description |
---|---|
Clear | All components in the container are deleted. |
EnsureVisible | Ensures that the current item in the container is visible. |
Lock | Prevents a container refreshing until the method UnLock has been called. |
UnLock | Unlocks 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
The container component has three special events: Activate, Click and Scroll.
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.
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.
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:
Figure 18.12.5.1: Project RSS reader - programme runtime
Figure 18.12.5.2: (Feed) form for the RSS reader project - development time.
Notes: