SelectedItems Property

Summary

Gets the items that are selected in the control.

Syntax

C#
C++/CLI
C++
public RasterImageListItemCollection SelectedItems { get; } 
[BrowsableAttribute(false)] 
public: 
property RasterImageListItemCollection^ SelectedItems { 
   RasterImageListItemCollection^ get(); 
} 
public:  
   property RasterImageListItemCollection^ SelectedItems 
   { 
      RasterImageListItemCollection^ get() 
   } 

Property Value

A RasterImageListItemCollection that contains the items that are selected in the control. If no items are currently selected, an empty RasterImageListItemCollection is returned.

Remarks

When the SelectionMode property is set to RasterImageListSelectionMode.Multi, this property returns a collection containing the items that are selected in the RasterImageList. For a single-selection RasterImageList, this property returns a collection containing the only selected item in the RasterImageList. For more information on the tasks that can be performed with the items in the collection, see RasterImageListItemCollection.

Example

C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
class MyForm2 : Form 
{ 
   RasterImageViewer viewer; 
   RasterImageList imageList; 
   RasterCodecs codecs; 
 
   public MyForm2() 
   { 
      // Set the size of the form 
      Size = new Size(400, 200); 
 
      // Create a new RasterImageList control 
      imageList = new RasterImageList(); 
      imageList.Dock = DockStyle.Left; 
      imageList.SelectionMode = RasterImageListSelectionMode.Single; 
      Controls.Add(imageList); 
      imageList.BringToFront(); 
 
      // Add a handler to the SelectedIndexChanged event 
      imageList.SelectedIndexChanged += new EventHandler(rasterImageList_SelectedIndexChanged); 
 
      Splitter splitter = new Splitter(); 
      splitter.Dock = DockStyle.Left; 
      Controls.Add(splitter); 
      splitter.BringToFront(); 
 
      viewer = new RasterImageViewer(); 
      viewer.Dock = DockStyle.Fill; 
      Controls.Add(viewer); 
      viewer.BringToFront(); 
 
      // Now load all our images 
      codecs = new RasterCodecs(); 
 
      string folderName = LEAD_VARS.ImagesDir; 
      string[] files = Directory.GetFiles(folderName, "*.*"); 
 
      // This is going to be a lengthy operation 
      // Suspend painting the RasterImageList 
      imageList.BeginUpdate(); 
 
      foreach (string fileName in files) 
      { 
         // Load the image as a thumbnail 
         RasterImage image = LoadThumbnail(fileName); 
 
         // Only add an item if we loaded the image successfuly 
         if (image != null) 
         { 
            // Create an item 
            RasterImageListItem item = new RasterImageListItem(); 
 
 
            // Setup the item information 
            item.Image = image; 
            item.Text = Path.GetFileName(fileName); 
            item.Page = 1; 
 
            // To load this image in original size later 
            item.FileName = fileName; 
 
            // Add the item into RasterImageList 
            imageList.Items.Add(item); 
         } 
      } 
 
      imageList.EndUpdate(); 
 
   } 
 
   private void rasterImageList_SelectedIndexChanged(object sender, EventArgs e) 
   { 
      // User has selected an item from the RasterImageList control. 
      // Re-load the item image and show it in original size in the viewer 
 
      // Get the selected item(s) 
      RasterImageListItemCollection selectedItems = imageList.SelectedItems; 
      if (selectedItems != null && selectedItems.Count == 1) 
      { 
         RasterImageListItem item = selectedItems[0]; 
 
         // Load the image in its original size and set it in the viewer 
         viewer.Image = codecs.Load( 
            item.FileName, 
            0, 
            CodecsLoadByteOrder.BgrOrGray, 
            1, 
            1); 
      } 
   } 
 
   private RasterImage LoadThumbnail(string fileName) 
   { 
      RasterImage image = null; 
 
      try 
      { 
         // See if we can load this image 
         CodecsImageInfo info = codecs.GetInformation(fileName, false, 1); 
 
         if (info.Format != RasterImageFormat.Unknown) 
         { 
            // Yes, calculate the thumbnail size to fit into RasterImageList.ItemImageSize 
            Rectangle rc = new Rectangle( 
               0, 
               0, 
               imageList.ItemImageSize.Width, 
               imageList.ItemImageSize.Height); 
 
            rc = RasterImageList.GetFixedAspectRatioImageRectangle(info.Width, info.Height, rc); 
 
            // Load the thumbnail 
            image = codecs.Load( 
               fileName, 
               rc.Width, 
               rc.Height, 
               24, 
               RasterSizeFlags.Resample, 
               CodecsLoadByteOrder.BgrOrGray, 
               1, 
               1); 
         } 
         else 
            image = null; 
      } 
      catch 
      { 
         image = null; 
      } 
      return image; 
   } 
} 
 
public void RasterImageList_Image() 
{ 
   MyForm2 form = new MyForm2(); 
   form.ShowDialog(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

Reference

RasterImageList Class

RasterImageList Members

Help Version 22.0.2023.2.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.