Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two combobox and data gride view using data source , each combobox display DGV values . i want when selecting an item in the first combobox , seconed one filter the values's relates to first one .
ex: countrycombobox , customercombobox
when selecting a country from countrycombobox ,customercombobox filter values and display customers relates to selected country ...
i'm looking for a perfect code for a while , thanks for the replays in advanced
Posted
Comments
Praveen Kumar Upadhyay 11-Dec-14 7:02am    
Bind second combobox on first combobox selected index change event. Pass value to second combobox what you have selected Text from first combobox.
Peter M. Adeeb 11-Dec-14 7:15am    
i don't use data binding on combobox , my code to add combobox items is:

connection.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = connection;
string query = "select * from client_details";
cmd.CommandText = query;
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
country_txt.Items.Add(reader["country_name"].ToString());
customer_txt.Items.Add(reader["customer_name"].ToString());
}
BillWoodruff 11-Dec-14 7:31am    
It appears to me that right now you are adding every possible customer_txt string to the second ComboBox: is that correct ?

I strongly suggest you look into 'DataView and 'RowFilter:

http://stackoverflow.com/a/4058503/133321
Peter M. Adeeb 11-Dec-14 7:39am    
i privent duplicates using this code for each combobox :
List<object> list = new List<object>();
{


foreach (object o in customer_txt.Items)
{
if (!list.Contains(o))
{
list.Add(o);
}
}
customer_txt.Items.Clear();
customer_txt.Items.AddRange(list.ToArray());
Praveen Kumar Upadhyay 11-Dec-14 8:49am    
What is your list.ToArray() while you are adding the List Range.

1 solution

SQL
1. on selectedindexchanged invent of first combo box,load data from database where condition is selected value of combo box (i.e countrycombobox)
2. bind this data to second combo box (i.e customercombobox)
 
Share this answer
 
Comments
Praveen Kumar Upadhyay 11-Dec-14 7:07am    
Don't just answer to get the points. This can be also written in the commentbox of the question.
vishal_pawar 11-Dec-14 7:12am    
do u have any problem with my solution?
Praveen Kumar Upadhyay 11-Dec-14 7:24am    
I don't have any problem with your answer. Don't fight dude but this is a sort of comment, which needs to put in the Question comment box.
BillWoodruff 11-Dec-14 7:38am    
I wonder if you read Praveen's comment, which was posted before you wrote this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900