I got a ListView in windows form. When a form loads a ListView upload with personel objects. I want to do it when a user double-clicks on a ListView, gets the personel object from the ListView.SelectedItem property and opens a new form and transfers this object to the newly opened form.
Here are my codes for loading Personel objects into a ListView:
public static void GetAll(ListView list)
{
list.Items.Clear();
using (FirebirdEntityz context = new FirebirdEntityz())
{
ObjectQuery<PERSONEL> query = context.PERSONEL;
foreach (var item in query)
{
var mylist = new ListViewItem { Text = item.NAME };
mylist.SubItems.Add(item.SURNAME);
mylist.Tag = item;
list.Items.Add(mylist);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
GetAll(listView1);
}
This is my personal object for transmitting:
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
PERSONEL personel = (PERSONEL)listView1.SelectedItems[0].Tag;
}
source
share