Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
shelwig  
#1 Posted : Sunday, June 8, 2008 4:29:35 PM(UTC)
shelwig

Rank: Member

Groups: Member
Joined: 2/23/2008(UTC)
Posts: 10

I have some code that changes the selected item in the Thumbnail ListView. (Users click on buttons and selected items move back and forth previewing the image in a BitmapViewer.)

Anyway, the problem starts if you try to combine using the buttons on the form and the arrow keys.

My code, when the button is clicked, simply gets the index of the currently selected item, increases it (provided it's not the last one) and calls:

myThumbnailList.Items[newIndex].Select = true;


This works fine until the user switches and starts using the arrow keys to change selection, at which point, the ThumbNailListview goes back to it's original selection - or the last one selected using the mouse or arrow keys, and scrolls from there.

Am I doing something wrong here?

A clue maybe, that when I programmatically change the selected item, the "SelectedItemsChanged" event does NOT fire.

Alex Kon  
#2 Posted : Tuesday, June 10, 2008 2:31:55 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

Yes, I have to confirm the issue with "SelectedItemsChanged" event - it will be fixed in next releases of the GraphicsMill for .NET.

As for the unconsistent behaviour - the reason is that you change selected item, but not focused one. And when user presses arrows keys - control uses focused item as start point.

Here is button click handler which moves selection & focus one item forward (where _tl is ThumbnailListView instance):

Code:
private void button2_Click(object sender, EventArgs e)
{
	if (_tl.SelectedIndices.Length > 0)
	{
		int oldIndex = _tl.SelectedIndices[0];
		int newIndex = Math.Min(oldIndex + 1, _tl.Items.Count - 1);
						
		_tl.Items[oldIndex].Selected = false;
		_tl.Items[newIndex].Selected = true;
		_tl.Items[newIndex].Focused = true;

		//... update BitmapViewer content here too...
	}
}
shelwig  
#3 Posted : Wednesday, June 11, 2008 8:58:12 PM(UTC)
shelwig

Rank: Member

Groups: Member
Joined: 2/23/2008(UTC)
Posts: 10

Perfect! Thanks Alex, .Focused did the trick. I can handle the event issue.
shelwig  
#4 Posted : Wednesday, June 11, 2008 9:03:03 PM(UTC)
shelwig

Rank: Member

Groups: Member
Joined: 2/23/2008(UTC)
Posts: 10

Actually, while we're on the subject, is there a way to ensure that the newly selected item is visible. (I.e. when you select the next item continuously, eventually it moves off the bottom of the control.)

shelwig  
#5 Posted : Wednesday, June 11, 2008 9:09:33 PM(UTC)
shelwig

Rank: Member

Groups: Member
Joined: 2/23/2008(UTC)
Posts: 10

Never mind, just discovered the thumbnailList EnsureVisible method.

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.