Quantcast
Channel: CSharp Forum Latest Questions
Viewing all articles
Browse latest Browse all 32088

which listview is sender ?

$
0
0
Hi all I have 3 listviews on my winforms app, I have 1 button called delete. So rather than make a method/button for each listview how can I use the listview name ie listview1 to pass to the button commands.


See my sample effort below it may make it clearer?



private void deleteordBut_Click(object sender, EventArgs e)
{
//var listView = sender as ListView;
var listView = sender as ListView;
MessageBox.Show(listView.ToString());  //trying to get which listview was clicked

if (listView == null) //if no listview was selected do nothing

{
return;

}

if (listView != null && listView.SelectedItems.Count == 0)  //same

{
MessageBox.Show(@"Order must be selected!");
return;

}
MessageBox.Show(@"Working" +(Convert.ToInt32(listView.SelectedItems[0].Text)));

}








Viewing all articles
Browse latest Browse all 32088

Trending Articles