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 fro
In the new form that will be opened, add a new property in the form class;
private PERSONNEL Personnel{get; set;}
public ShowPersonnel(PERSONNEL _personnel){
this.Personnel = _personnel;
//do whatever you want here
}
In the main form;
private void listView1_SelectedIndexChanged(object sender, EventArgs e){
PERSONNEL personnel = listView1.SelectedItems[0].Tag as PERSONNEL;
Form2 form2 = new Form2();
form2.ShowPersonnel(personnel);
form2.Show();
}
May include typos. Change PERSONNEL to PERSONEL.
You could probably just add a public PERSONEL
property to the form, which you would then set in your SelectedIndexChanged
event handler. Then any code that has access to your selector form could access your custom selected PERSONEL
property.
You should be able to set the display member of the listview control. Berfore you enter the for loop do something like:
list.DisplayMember = "Name"
Then bind the object.
list.DataSource = query.ToList()
The selected item will give you the object you've binded...
MessageBox.Show(((PERSONEL)list.SelectedItem).Name);
This was how it worked in .net 2.0. But I am sure there is probably a way to do this in 3.0 and greater...