ListView

J

joseph.inglis

Hi group,

Someones gonna answer this in two seconds flat but im tearing my hair out.
Create a form, add a listview, add 5 items and programmatically select item
at index 3.

this.imageList.Items[3].EnsureVisible();
this.imageList.Items[3].Selected = true;

That works fine. Use the mouse to select index 4 and again, works sweetly.

Whats happening in the above scenario is that the mouse index is still set
to 0. From application start and setting to index 3 as stated... the first
time i press down arrow key the KeyUp event reports index 1.

lastIndex= imageList.SelectedItems[0].Index;

Thats right eh. The mouse index is still at 0... as i press the down key,
the image list quickly selects index 1 just before the keyup event fires and
this is correctly reporting index 1. The image list does infact quickly
select index 1 (it turns blue) just before the key up event... why and how
can i stop/prevent/work around this?

Am stuck

Tam
 
S

Shakir Hussain

Joesph,

The selection of an item can occur

1. By clicking (combination of mousedown + mouse up)
2. from keyboard arrows.Combination of keydown+keyup.

If you retrieve the intermediate values for mousedown or key down, you may
get the old index not the new one. Thats becoz, the selection process is
just half way. You have to complete till keyup or mouseup for an item to get
new selection index.

Shak.
 
J

joseph.inglis

Thanks for reply shak (my names Tam btw).

I think Shak I see what you mean and thats not the problem im having.

Ill try and explain.

From form load add an empty list, add 5 items to it and use code
this.imageList.Items[3].EnsureVisible();
this.imageList.Items[3].Selected = true;

to set item 3. Display the form and thats cool, the item displayed and
highlighted is item 3. The dotted mouse box is nowhere to be seen.

If I now press the down key, with nothing capturing any event, the item that
is selected is item 2 and not 4. This is highligted.

If i press the up key instead, then the dotted mouse box appears at item 0
and the orignal item 3 remains selected.

Whats going on here... its as if something is still set somwhere to index 0.
Am I missing something?

Tam

Shakir Hussain said:
Joesph,

The selection of an item can occur

1. By clicking (combination of mousedown + mouse up)
2. from keyboard arrows.Combination of keydown+keyup.

If you retrieve the intermediate values for mousedown or key down, you may
get the old index not the new one. Thats becoz, the selection process is
just half way. You have to complete till keyup or mouseup for an item to get
new selection index.

Shak.


joseph.inglis said:
Hi group,

Someones gonna answer this in two seconds flat but im tearing my hair out.
Create a form, add a listview, add 5 items and programmatically select item
at index 3.

this.imageList.Items[3].EnsureVisible();
this.imageList.Items[3].Selected = true;

That works fine. Use the mouse to select index 4 and again, works sweetly.

Whats happening in the above scenario is that the mouse index is still set
to 0. From application start and setting to index 3 as stated... the first
time i press down arrow key the KeyUp event reports index 1.

lastIndex= imageList.SelectedItems[0].Index;

Thats right eh. The mouse index is still at 0... as i press the down key,
the image list quickly selects index 1 just before the keyup event fires and
this is correctly reporting index 1. The image list does infact quickly
select index 1 (it turns blue) just before the key up event... why and how
can i stop/prevent/work around this?

Am stuck

Tam
 
M

Morten Wennevik

Oh yeah, sorry Tam, I forgot to check if you signed with a different name than your sender name.
 
J

joseph.inglis

Add this to your code

this.imageList.Items[3].Focused = true;
Thanks Morten, that snagged it... Wouldnt have thought to set both Focus and
Focused but... of course it makes sense when you think about it.

Jobs a good 'un.

Tam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top