开发者

Auto activate an item on select in a ListView

Is it possible that in a ListView whenever an Item has been selected (e.g mouse 1 left click or Key down or key up, left right) that item gets activated (Like when you hit enter or double click!). What even开发者_高级运维t or properties of ListView will do this, if any?

UPDATE

I found out it will work if ListView.Activation is set to OneClick but thi is only for the mouse, I want the same with keyboard arrows too.


You can do that by listening the the ItemSelectionChanged event and simply calling the code that runs whenever an item is double-clicked.

Alternatively you can call ItemActivate event that fires when an item is double-clicked using this bit of code, although I'd recommend the first method:

private void ListView1_ItemSelectionChanged(Object sender, ListViewItemSelectionChangedEventArgs e) 
{
    ListView1_ItemActivate(sender, e);
}


You, have mouseclick and mousedoubleclick events in the listview control for this purpose.


Implement the following events with whatever you want your listview to do.

KeyDown , KeyUp, KeyPress, MouseDown, MouseUp, MousePress, MouseHover, MouseEnter, MouseClick, MouseDoubleClick

those are only a few select examples.

Lets say your listview is named listView1

to Subscribe to one of the events, do this

private void Form1_Load(object sender, EventArgs e)
{
    listView1.KeyDown += new KeyEventHandler(listView1_KeyDown);
}

void listView1_KeyDown(object sender, KeyEventArgs e)
{
    throw new NotImplementedException();
}

Enter your content at the throw statement

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜