In this Article, we will see How to bind data in ComboxBox from database in C# Windows Form Application. In previous post, we saw How to:
- Create a simple Windows Form Login Application in C#
- Insert, Update and Delete Record in DataGridView C#
- Search Record in DataGridView C#.
1. Go to New -> Project -> Select Windows Form Application.
2. Create a Database (named as Sample). Add a Table tbl_Country. The following is the table schema for creating tbl_Country.
3. Drop Label and ComboBox control from the toolbox.
In the above code, I have created fillComboBox() method for filling the ComboBox with data and also created cmb_Country_SelectedIndexChanged event which fires when the SelectedIndex property changed.
public partial class Form1 : Form
private void Form1_Load(object sender, EventArgs e)
//fillComboBox method for filling the ComboBox with Data
private void fillComboBox()
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Sample;Integrated Security=true;"))
SqlDataAdapter adapt = new SqlDataAdapter("Select * from tbl_Country", con);
DataTable dt = new DataTable();
//Set Displaymember as Country
cmb_Country.DisplayMember = "Country";
//Set ValueMember as ID
cmb_Country.ValueMember = "ID";
cmb_Country.DataSource = dt;
private void cmb_Country_SelectedIndexChanged(object sender, EventArgs e)
lbl_DisplayValue.Text = cmb_Country.SelectedValue.ToString();
Hope you like it. Thanks.
[Download Source code via Google Drive]