Persist "FocusedIndex" in ThumbnailViewer

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
jchristian
Posts: 6
Joined: Mon Oct 24, 2016 11:38 pm

Persist "FocusedIndex" in ThumbnailViewer

Post 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.
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Persist "FocusedIndex" in ThumbnailViewer

Post 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
jchristian
Posts: 6
Joined: Mon Oct 24, 2016 11:38 pm

Re: Persist "FocusedIndex" in ThumbnailViewer

Post 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!!
Post Reply