Answer the question
In order to leave comments, you need to log in
How to create ComboBox items from SQLite?
I need to fill the ComboBox from the lines of the SQLite database, I can’t understand what I’m doing wrong (
public SQLiteConnection cmb;
private void comboBoxGroups_Selected(object sender, RoutedEventArgs e)
{
Group group = new Group();
using(var statement = cmb.Prepare("SELECT NameGroup FROM Groupt"))
{
statement.Bind(1, group.NameGroup);
while(statement.Step()==SQLiteResult.ROW)
{
comboBoxGroups.Items.Add(group.NameGroup);
}
}
}
Answer the question
In order to leave comments, you need to log in
First, get the result of your query from the database into a table or collection. Moreover, it is desirable not only names, but also identifiers. SELECT ID,NameGroup FROM Groupt
Then, in the DataSource property, specify where you put the data. Set the DisplayMember field to NameGroup and set the ValueMember to ID.
Thus, when the user selects a Group Name, you can read its ID.
This is for WinForms. For WPF, it's a little different.
PS I wrote from memory, I could make a mistake somewhere
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question