when I click the items in chaptercheckboxlist1 that chapters containing questions should display in another checkboxlist
How to do this using windows form application c# with Access database
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jul 11, 2012, 5:06 AM
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Combobox
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select sub from subject group by sub";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
checkedListBox1.Items.Add(reader["sub"].ToString());
}
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
checkedListBox2.Items.Clear();
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from subject where sub='" + checkedListBox1.SelectedItem + "'";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
checkedListBox2.Items.Add(reader["chapter"].ToString());
}
con.Close();
reader.Close();
}
}
}
Thanks
If this post helps you mark it as answer