Figure 17.4.1.1: ListView with selected entry (after a search)
The project demonstrates how you can work with a ListView:
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:
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.