How to save selected items from ListBox on winforms using Entity
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();
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


Jignesh KumarRank #91 · 22.9K reputationPosted Sep 13, 2020, 6:46 PM EDT