C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

load combobox


Posted Date: 16 Dec 2008      Posted By: Carmel Beeshow      Member Level: Silver     Points: 1   Responses: 3



if in one combobox i am loading table(fruit,flowers,vehicles)
and if suppose i select FRUIT from this combobox1.then in the combobox2.it should LOAD the related fruits table.

PLEASE SEND ME THE SOURCE CODE IN C#.NET





Responses

Author: rishika    16 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     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 2008Member Level: DiamondRating: 2 out of 52 out of 5     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



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Life cycle
Previous : ACTIVE DIRECTORY USER
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use