How can I store the checked items of my checkbox list? I dont have a class so I can't use ListItems. My checkbox list is populated using my database (MS Access).
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = @"SELECT CONTENT FROM " + tab + " GROUP BY CONTENT ORDER BY MIN(CHAP)";
OleDbDataAdapter dAdap = new OleDbDataAdapter(command);
DataSet dSet = new DataSet();
dAdap.Fill(dSet);
for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
{
chkList.Items.Add(dSet.Tables[0].Rows[i][0].ToString()); //This is the part where the items are populated
}
connection.Close();
edit using foreach
foreach (string chk in chkList.CheckedItems)
{
MessageBox.Show(chk.ToString()); //This gets every string checked, but one after another
top = chk;
}
for my query
"SELECT TOP " + num + " QUESTION,C1,C2,C3,C4,ANSWER,CONTENT FROM " + tab + " WHERE CONTENT = '" + top + "'"
it only query the last item checked.
edit to count the items checked
MessageBox.Show(chkList.CheckedItems.Count.ToString());
string[] topic = new string[chkList.CheckedItems.Count];
for (int i = 0; i < topic.Length; i++)
{
topic[i] = //How to get the text for each checked items?
}