A
Alberto
I need a listview where the user can select the items with the arrow keys
but I also want that it works in a circular way: if you are in the first
item and press key up, the last item is selected (the same with the last
one).
I wrote this code for the keyDown event of the listView:
if (lst.SelectedIndices.Count > 0)
{
if (lst.SelectedIndices[0] == 0 && e.KeyCode == Keys.Up)
{
lst.Items[lst.Items.Count-1].Selected = true;
}
else
{
if (lst.SelectedIndices[0] == lst.Items.Count-1 &&
e.KeyCode == Keys.Down)
{
lst.Items[0].Selected = true
}
else
{
if (e.KeyCode == Keys.Down)
lst.Items[lst.SelectedIndices[0]
+ 1].Selected = true;
else
if (e.KeyCode == Keys.Up)
lst.Items[lst.SelectedIndices[0]
-1].Selected = true;
}
}
}
But there are two problems:
1) when the first item is selected and press key up two times and then press
key down.
2) when the last item is selected and press key down two times and then
press key up.
Can anybody tell me whats wrong?
Thank you very much.
but I also want that it works in a circular way: if you are in the first
item and press key up, the last item is selected (the same with the last
one).
I wrote this code for the keyDown event of the listView:
if (lst.SelectedIndices.Count > 0)
{
if (lst.SelectedIndices[0] == 0 && e.KeyCode == Keys.Up)
{
lst.Items[lst.Items.Count-1].Selected = true;
}
else
{
if (lst.SelectedIndices[0] == lst.Items.Count-1 &&
e.KeyCode == Keys.Down)
{
lst.Items[0].Selected = true
}
else
{
if (e.KeyCode == Keys.Down)
lst.Items[lst.SelectedIndices[0]
+ 1].Selected = true;
else
if (e.KeyCode == Keys.Up)
lst.Items[lst.SelectedIndices[0]
-1].Selected = true;
}
}
}
But there are two problems:
1) when the first item is selected and press key up two times and then press
key down.
2) when the last item is selected and press key down two times and then
press key up.
Can anybody tell me whats wrong?
Thank you very much.