i got a ListView in the windows form.When form loads ListView loading with personel objects. I want to do when some user double clicks on ListView , gets the personel object from the ListView.SelectedItem property and open a new form and transfer this object to newly opened form.
here is my codes for loading personel objects to 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 personel object for transfer:
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
PERSONEL personel = (PERSONEL)listView1.SelectedItems[0].Tag;
}