Hi Sermaraj,
If I have understood your quersion clearly then you want to fill the first dropdown box using internal list collection (without using any database table and SQL command)
then you want second dropdown box to be filtered based on selection of first list box but that too should manage internally withing C# code (without using using SQL command)
so if this is true then here is your solution
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;
namespace _26196_filtering_collections_in_c_sharp
{
public partial class Form1 : Form
{
public static List<CarModel> lstCarModel = new List<CarModel>();
public Form1()
{
InitializeComponent();
lstCarModel.Add(new CarModel("MARUTHI", "800"));
lstCarModel.Add(new CarModel("FORD", "FIGO"));
this.comboBox1.DataSource = lstCarModel;
this.comboBox1.DisplayMember = "Car";
this.comboBox1.ValueMember = "Car";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
List<CarModel> FilteredCarModel = lstCarModel;
var filtered = from CarModel cm in lstCarModel
where cm.Car == comboBox1.Text.ToString()
select cm;
this.comboBox2.Items.Clear();
foreach (CarModel carmodel in filtered)
{
this.comboBox2.Items.Add(carmodel.Model.ToString());
}
}
public class CarModel
{
string car;
public string Car{get { return car; }}
string model;
public string Model{get { return model; }}
public CarModel(string car, string model){this.car= car;this.model= model;}
public override string ToString(){return string.Format("{0}: {1}", car, model);}
}
}
}