i am doing application using List box in c sharp in windows application.
Design as follows;
Listbox1 Buttons Listbox2
Ram ADD
Sam ADD ALL
Suresh Remove
Vignesh Remove All
Load
Clear
SqlConnection con = new SqlConnection(" Data Source=INDIA;Initial Catalog=HIMTTESTing;Integrated Security=True");
Code as follows for button(Load)
private void Btn_Load_Click(object sender, EventArgs e)
{
string sql = "select Faculty_Name from Tb_SCH_Faculty_List";
DataSet mydataset = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
adp.Fill(mydataset,"Tb_SCH_Faculty_List");
DataTable mydatatable = mydataset.Tables[0];
DataRow temprow = null;
foreach (DataRow tempRow_Variable in mydatatable.Rows)
{
temprow = tempRow_Variable;
Lb_Faculty_Name.Items.Add((temprow["Faculty_Name"]));
}
}
Code as follows for button(ADD ALL)
private void Btn_Add_All_Click(object sender, EventArgs e)
{
string com = " Select Faculty_Name from Tb_SCH_Faculty_List";
DataSet mydataset = new DataSet();
SqlDataAdapter adpt = new SqlDataAdapter(com, con);
adpt.Fill(mydataset, "Tb_SCH_Faculty_List");
DataTable mydatatable = mydataset.Tables[0];
DataRow temprow = null;
foreach (DataRow tempRow_Variable in mydatatable.Rows)
{
temprow = tempRow_Variable;
Lb_Selected_Faculty.Items.Add((temprow["Faculty_Name"]));
}
}
Both Load and ADD All Button working fine.
Output shows as;
when i click the Load (Button)all faculty name is retrieved from the data base and displayed in the Lisbox1.
similarly when i click the ADD ALL (Button)all faculty name is displayed in the Lisbox2.
the above two buttons Load and ADD ALL is working fine.
in the ADD button;
when i click the Load button all names are retrieved from the data base and displayed in the Listbox1,in the Listbox1 when i select a Particular name and click the ADD button the particular name want to display in to the Listbox2.
for the particular name displaying how to do.please help me.
/Edit Pre tag added by Jibesh