It is the normal behavior on windows, but not in the ListView control, I'm wondering why ... maybe an option that I've miss somewhere ?
anyway, here is my solution, you can either override the listview, or put an event handler on the mouseUp event:
First way:
public class MyListView : System.Windows.Forms.ListView
{
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (e.Button == MouseButtons.Right)
{
ListViewItem item = this.GetItemAt(e.X, e.Y);
if (item != null)
{
item.Selected = true;
}
}
}
}
Second way :
this.listView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnListViewMouseUp);
private void OnListViewMouseUp(object sender, MouseEventArgs e)
{
ListView listView = sender as ListView;
if (e.Button == MouseButtons.Right)
{
ListViewItem item = listView.GetItemAt(e.X, e.Y);
if (item != null)
{
item.Selected = true;
}
}
}
mercredi 24 septembre 2008 | Predicate<T>
Cher Entreprenaute, vous pouvez trouver ici votre passeport pour l'economie numerique
Smart Code Generator
Serialcoder participe activement au projet opensource Smart Code Generator
smartcodegenerator