Page 1 of 1

Persist "FocusedIndex" in ThumbnailViewer

Posted: Tue Oct 25, 2016 12:07 am
by jchristian
Hello,

I am using a thumbnailviewer and I've been trying to figure out how to keep the next selected thumbnail active after you remove a selected thumbnail.
For example I click to select a thumbnail (my highlight box is colored red), I then have a button event that removes the selected thumbnail from the viewer, but then I have to click again to select the next thumbnail to perform the delete again. Is there a way to keep that selection persistent so that I could keep clicking the delete button without having to click the next thumbnail?

Here is a snippet of C# code I am currently using:

Code: Select all

			
			var images = tvRight.GetSelectedImages();
			if (images.Length == 0)
				return;

			for (var count = 0; count < images.Length; count++)
			{
				tvRight.Images.Remove(images[count]);
			}
			
			tvRight.Focus();
			tvRight.FocusedIndex = 0;
			
"tvRight" is the thumbnailviewer control.


Let me know if you need more information.


Thank You.

Jamie C.

Re: Persist "FocusedIndex" in ThumbnailViewer

Posted: Tue Oct 25, 2016 10:43 am
by Alex
Hello Jamie,

I think you need save the index of focused thumnail before thumbnail removal and restore index after the thumbnail removal:

Code: Select all

         var images = tvRight.GetSelectedImages();
         if (images.Length == 0)
            return;

         int focusedIndex = tvRight.FocusedIndex;

         for (var count = 0; count < images.Length; count++)
         {
            tvRight.Images.Remove(images[count]);
         }
         
         tvRight.Focus();
         if (focusedIndex >= 0 && focusedIndex < tvRight.Images.Count)
             tvRight.FocusedIndex = focusedIndex;
         else
             tvRight.FocusedIndex = 0;
Best regards, Alexander

Re: Persist "FocusedIndex" in ThumbnailViewer

Posted: Tue Oct 25, 2016 7:07 pm
by jchristian
Thanks for the reply Alex, unfortunately that didn't work, I did however find a different way of doing it.

Code: Select all

         
         var images = tvRight.GetSelectedImages();
         if (images.Length == 0)
            return;

         for (var count = 0; count < images.Length; count++)
         {
            tvRight.Images.Remove(images[count]);
         }
         
         tvRight.Focus();
         
         // Adding this //
	tvRight.SelectedIndices.add(tvRight.FocusedIndex);
	
Manually adding the selected index based off of the focused index, made the selected thumbnail stay on the 0 indexed image.
Which works perfectly for what I need.

Thanks for your help Alex!!