How to bind ComboBox using edmx in windows form c#
IntroductionIn my previous article i have already explained about bind combo box with entity framework using code first approach. also bind combo box with ado.net. Now, today i am discussing about edmx file. Before bind the combo box with edmx file , first to add edmx file in the solution or you can say project. Now, add a combo box in the form.
Copy the following code and paste in class constructor after InitializeComponent(); method.
Student_DBEntities dc = new Student_DBEntities();
var item = dc.Student_record;
comboBox1.DataSource = item.ToList();
comboBox1.DisplayMember = "Student_Name";
Now, Code generate the following output:
The following video cover all such types of things which is mentioned in the article, i am giving you this video for better understanding:
- Student_DBEntities is a context class through which we can access or manipulate database record. (Check the context file in your solution).
- Student_record is a public property through which we can communicate database table.