Mo Bahgat

Mo Bahgat

  • NA
  • 55
  • 736

How to save selected items from ListBox on winforms using Entity

Sep 13 2020 3:36 PM
This is what I codding in form public partial class Form1 : Form { TestDBEntities db = new TestDBEntities(); tblData td = new tblData(); } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //Binding Data to List Box listbox1.DataSource = db.Countries.ToList(); listbox1.DisplayMember = "CtrName"; listbox.ValueMember = "CtrId"; } private void btnSave_Click(object sender, EventArgs e) { td.Country = listbox1.SelectedItems.ToString(); db.tblData.Add(td); db SaveChange(); }

Answers (1)