User Tools

Site Tools


k17:k17.4:k17.4.1:start

17.4.1 Project - Excursion ListView

b1

Figure 17.4.1.1: ListView with selected entry (after a search)

The project demonstrates how you can work with a ListView:

  • Insert an element - Text also in RichText format,
  • to select an element,
  • Set the selection mode (single or multiple),
  • delete the current element,
  • rename the current element,
  • search for an element,
  • Formatted output of all elements of a ListView (console),
  • Export of all elements in ListView in JSON format → chapter 24.9.0 JSON. The ListView data including its hierarchy is stored in an export.dat file in the project directory,
  • Import of all elements (JSON format) and display of the imported elements in the ListView in the original hierarchy.
  • Remove selection for all elements,
  • switch sorting of elements in the ListView on and off.

Clicking an item in the ListView displays selected information about the selected item in the console of the Gambas IDE:

Key = KX1 | Text = X1-Element | Bild-Pfad = icon:/22/record
Key = KY1 | Text = Y1-Element | Bild-Pfad = icon:/22/record
Key = KY31 | Text = Y31-Element | Bild-Pfad = icon:/22/linux
...

The quite extensive source code can be found in the project' ListViewE' in the download area. The source code is adequately commented. For example, the following source code section inserts new elements into the ListView:

Public Sub btnInsertElement_Click()
 
  If txbElement.Text <> Null Then
     If Not ListView1.Exist("K" & txbElement.Text) Then
        ListView1.MoveCurrent()
        ListView1.Add("K" & txbElement.Text, , Picture["icon:/22/info"], ListView1.Key)
        ListView1.Item.EnsureVisible()
     Else
        Message.Warning("Das Element '" & txbElement.Text & "' existiert bereits!")
        txbElementName.Clear() 
        Return
     Endif 
     txbElementName.Clear() 
   ' Das neue Element wird markiert
     ListView1.Key = ListView1.Item.Key
  Endif
 
End ' btnInsertElement_Click()

You should decide in good time whether you want the elements to be displayed sorted after inserting or not. You cannot use the' Sorted' property as a switch between sorted and unsorted display. By clicking on the check box with the label' Sort elements' you can change the display once to sorted display. Any further change of the value (true or false) of the CheckBox - interpreted as' sort' or' do not sort' - has the following effect:

  • Value 'sort': Each new element is inserted according to the sort order.
  • Value 'not sort': Each new element is inserted after the selected element.

For your own projects, you have to select the passages from the source code you need.

Note: The Current property represents the user-selected entry in a ListView, while the Item property of the _TreeView_Item type is an internal, invisible and current-independent pointer. Current is used to evaluate user input in a ListView and item for all algorithms that run through a ListView.

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.
k17/k17.4/k17.4.1/start.txt · Last modified: 30.09.2023 by emma

Page Tools