Windows Develop Bookmark and Share   
 index > Windows Forms General > A few ListView questions
 

A few ListView questions

1) How do I get the old name of a edited ListViewItem?
2) How do I have a seperate context menu for the column headers? In fact, how do I tell when a user right-clicks on a ColumnHeader?

There doesn't seem do be any obvious ways to do the above, and I'm a bit new to Windows.Forms.
thebeginingoftheend  Thursday, July 26, 2007 8:45 AM
This is all possible with standard events. In this code, I assume contextMenuStrip1 is the ContextMenuStrip for listView1 and contextMenuStrip is a second strip for use when the column header is clicked.

private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e) {
Console.WriteLine("Item {0} changed from {1} to {2}", e.Item, listView1.Items[e.Item].Text, e.Label);
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) {
// Check if header area was clicked
Point pos = listView1.PointToClient(Control.MousePosition);
Rectangle rect = listView1.TopItem.Bounds;
if (pos.Y < rect.Top) {
e.Cancel = true;
contextMenuStrip2.Show(listView1, pos);
}
}

nobugz  Thursday, July 26, 2007 7:00 PM
This is all possible with standard events. In this code, I assume contextMenuStrip1 is the ContextMenuStrip for listView1 and contextMenuStrip is a second strip for use when the column header is clicked.

private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e) {
Console.WriteLine("Item {0} changed from {1} to {2}", e.Item, listView1.Items[e.Item].Text, e.Label);
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) {
// Check if header area was clicked
Point pos = listView1.PointToClient(Control.MousePosition);
Rectangle rect = listView1.TopItem.Bounds;
if (pos.Y < rect.Top) {
e.Cancel = true;
contextMenuStrip2.Show(listView1, pos);
}
}

nobugz  Thursday, July 26, 2007 7:00 PM
Thanks for the help. That listView.TopItem stuff will be very useful for my project.
thebeginingoftheend  Friday, July 27, 2007 4:57 AM

You can use google to search for other answers

Custom Search

More Threads

• Drag an image onto another image and join
• Newsgroup available via NNTP?
• Suddenly Icons disappear ??
• How to load applications Inside another
• Outlook look&feel with Whidbey
• Component/Control diff&#233;rences
• How to detect idle user time?
• Special Characters
• Internet Application - need help, simple question
• Selected Item in a List Box