| Author: rishika 16 Dec 2008 | Member Level: Gold | Rating:  Points: 3 |
in combobox2_selectedindexchanged event write code like this
if(combobox1.text==fruit) { //fill the values of fruits in combobox2; combobox2.items.add("Apple"); } else if(combobox1.text==flower) { //fill the values of flowers in combobox2 } else if(combobox1.text==vehicles) { //fill the values of vehiclesin combobox2 }
|
| Author: Asal-2009 16 Dec 2008 | Member Level: Diamond | Rating:  Points: 6 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } DataTable dt = new DataTable(); DataSet ds = new DataSet(); string x=null; private void Form1_Load(object sender, EventArgs e) { if (comboBox1.Items.Count == 0) { comboBox1.Items.Add("Personaldetails"); comboBox1.Items.Add("Personaldetails1"); comboBox1.Items.Add("Personaldetails2"); }
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection con; SqlDataAdapter da; con = new SqlConnection("server=asdfasdf;uid=asdf;password=asdf;database=asdfasdf;"); con.Open(); if (x == null) { x = "SELECT username,password FROM " + comboBox1.SelectedItem.ToString() + " ";
da = new SqlDataAdapter(x, con);
da.Fill(ds); } dt = ds.Tables[0]; comboBox2.DataSource = dt; comboBox2.DisplayMember = dt.Columns[0].ToString(); comboBox2.ValueMember = dt.Columns[1].ToString();
} } }
G.Rajan Happy New Year
|