Reputation: 187
I need to get the sender tag from the colums in a ListView, how can I do this?
I mean something like this:
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
if((string)(sender as ColumnHeader).Tag == "...")
{
/*mycode*/
}
}
Upvotes: 1
Views: 694
Reputation: 125342
The sender of the event is ListView
. You should use e.Column
which is the index of clicked column and find the column object, then get the value from tag
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
var column = listView1.Columns[e.Column];
var tag = column.Tag as string;
if(tag == "something")
{
//...
}
}
Upvotes: 1
Reputation: 16986
Look for ColumnClickEventArgs.Column
which returns zero-based index of the column that is clicked.
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
if(e.Column >=0 && ListView1.Columns[e.Column].Tag == "...")
{
/*mycode*/
}
}
Upvotes: 1