Is it possible to fill an existing combobox with a method from a class? Whenever I try, I get a message that the item (combobox) does not exist. The method of how I want to fill the combobox works basically. However, I do not know how to address the combobox from the method of the class.
you just give the ui control to your method.
means the method get one parameter/argument.
call your method with the name used in the window.
in the designer you see also the classname.
@Markus Rauch
I don’t get it. Here is my code which works perfect if it is not in a class:
Dim dbFile As FolderItem
Dim db As New SQLiteDatabase
dbFile = GetFolderItem("airports_database.sqlite")
db.DatabaseFile = dbFile
db.EncryptionKey="HierStehteinPasswort"
If db.Connect Then
dim ps as PreparedSQLStatement
ps = SQLitePreparedStatement(db.Prepare( "SELECT * FROM tblRunways WHERE txtAirport LIKE ?" ))
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(0, txtDepartureAirport.text)
dim rs as RecordSet = ps.SQLSelect
If rs <> Nil Then
While Not rs.EOF
ComboBoxDepartureRunways.AddRow rs.field("txtRwy_Ident").value
rs.MoveNext
Wend
rs.close
Else
MsgBox("The database couldn't be opened. Error: " + db.ErrorMessage)
End If
end if
The code reads from a sqlite database all runways of an airport and adds them to a Combobox. If I add this code to a method in a class I get the bug - item does not exist - in the line
ComboBoxDepartureRunways.AddRow rs.field("txtRwy_Ident").value
Greeting from Hermannsburg (Lower Saxony)
Gerson Nerger
First, consider moving your db and it’s connection code out into either Window1.db (if your app only has one window) or App.db so that you can use it for other objects as well.
Next, consider an object-oriented approach in which you subclass ComboBox as RunawaysComboBox. This will be a special version of ComboBox that knows how to fetch it’s own data from the table. You can create a method within it called, ‘FetchRunaways’ that does all the work of communicating with the database and adding all the rows to the ComboBox.
Public Sub FetchRunaways(txtDepartureAirport As Text)
Dim ps As PreparedSQLStatement
ps = SQLitePreparedStatement(App.db.Prepare( "SELECT * FROM tblRunways WHERE txtAirport LIKE ?" ))
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(0, txtDepartureAirport.Text)
Dim rs As RecordSet = ps.SQLSelect
If rs <> Nil Then
While Not rs.EOF
Me.AddRow rs.field("txtRwy_Ident").value
rs.MoveNext
Wend
rs.close
Else
MsgBox("The database couldn't be opened. Error: " + db.ErrorMessage)
End If
End Sub
Add a ComboBox to your window and make it’s super, ‘RunawaysComboBox’.
When you want it to load/refresh it’s contents, simply run it’s method…
ComboBoxDepartureRunways.FetchRunaways(txtDepartureAirport)
Hope this helps.
Greetings from Burlington, Ontario
@Kristin Green
Okay, it took a while, but now I got it. Thank you very much for your help.
Now I have a new problem related to the old: If I use two combo boxes, create a separate subclass for each and name them separately and also name the methods and transfer parameters differently and also set the supers separately, both combo boxes still get the same content the moment I fill the first one.
you can use the same subclass, just add a different method there.
Did it again from the scratch and now it works. Thanks!