Leadtools.WinForms Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
SelectionMode Property
See Also  Example
Leadtools.WinForms Namespace > RasterImageList Class : SelectionMode Property



Gets or sets whether automatic item selection is allowed.

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Behavior")>
<DescriptionAttribute("Indicates if the control is to be single-select, multi-select or unselectable.")>
Public Property SelectionMode As RasterImageListSelectionMode
Visual Basic (Usage)Copy Code
Dim instance As RasterImageList
Dim value As RasterImageListSelectionMode
 
instance.SelectionMode = value
 
value = instance.SelectionMode
C# 
[CategoryAttribute("Behavior")]
[DescriptionAttribute("Indicates if the control is to be single-select, multi-select or unselectable.")]
public RasterImageListSelectionMode SelectionMode {get; set;}
C++/CLI 
[CategoryAttribute("Behavior")]
[DescriptionAttribute("Indicates if the control is to be single-select, multi-select or unselectable.")]
public:
property RasterImageListSelectionMode SelectionMode {
   RasterImageListSelectionMode get();
   void set (RasterImageListSelectionMode value);
}

Return Value

An RasterImageListSelectionMode enumeration that indicates whether automatic item selection is allowed. Default value is RasterImageListSelectionMode.Single.

Example

This example shows how to perform manual selection on a RasterImageList control.

Visual BasicCopy Code
Private Class MyForm5 : Inherits Form
    Private imageList As RasterImageList
    Private codecs As RasterCodecs
    Public Sub New(ByVal title As String)
        Text = title

        ' Set the size of the form
        Size = New Size(400, 200)

        ' Create a new RasterImageList control
        imageList = New RasterImageList()
        imageList.Dock = DockStyle.Fill
        imageList.SelectionMode = RasterImageListSelectionMode.Single
        imageList.Size = Size
        Controls.Add(imageList)
        imageList.BringToFront()

        RasterCodecs.Startup()
        codecs = New RasterCodecs()

        ' Create three items
        Dim imagesPath As String = LeadtoolsExamples.Common.ImagesPath.Path

        For i As Integer = 0 To 2
            ' Load the image
            Dim index As Integer = i + 1
            Dim imageFileName As String = imagesPath & "Image" & index.ToString() & ".cmp"
            Dim image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
            Dim item As RasterImageListItem = New RasterImageListItem(image, 1, "Item" & index.ToString())

            ' Select the first item
            If i = 0 Then
                item.Selected = True
            End If

            ' Add the item to the image list
            imageList.Items.Add(item)
        Next i

        RasterCodecs.Shutdown()

        ' Use manual selection
        imageList.SelectionMode = RasterImageListSelectionMode.None

        ' Add a handler to the MouseDown event
        AddHandler imageList.MouseDown, AddressOf rasterImageList_MouseDown

        ' Add the RasterImageList to the control collection.
        Controls.Add(imageList)
    End Sub

    Private Sub rasterImageList_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim imageList As RasterImageList = CType(IIf(TypeOf sender Is RasterImageList, sender, Nothing), RasterImageList)

        ' Check if we are in manual selection mode and if this is a left button click
        If imageList.SelectionMode = RasterImageListSelectionMode.None AndAlso e.Button = Windows.Forms.MouseButtons.Left Then
            ' Yes, get the item under the cursor position
            Dim item As RasterImageListItem = imageList.HitTest(e.X, e.Y)

            ' If not already selected, select this item
            If Not item Is Nothing AndAlso (Not item.Selected) Then
                imageList.BeginUpdate()

                ' First, de-select any items
                imageList.SelectAll(False)

                ' Now select this item
                item.Selected = True

                imageList.EndUpdate()

                item.Invalidate()
            End If
        End If
    End Sub
End Class

Public Sub RasterImageList_SelectionMode(ByVal title As String)
    Dim form As MyForm5 = New MyForm5(title)
    form.ShowDialog()
End Sub
C#Copy Code
class MyForm5 : Form 

   RasterImageList imageList; 
   RasterCodecs codecs; 
   public MyForm5(string title) 
   { 
      Text = title; 
 
      // Set the size of the form 
      Size = new Size(400, 200); 
 
      // Create a new RasterImageList control 
      imageList = new RasterImageList(); 
      imageList.Dock = DockStyle.Fill; 
      imageList.SelectionMode = RasterImageListSelectionMode.Single; 
      imageList.Size = Size; 
      Controls.Add(imageList); 
      imageList.BringToFront(); 
 
      RasterCodecs.Startup(); 
      codecs = new RasterCodecs(); 
 
      // Create three items 
      string imagesPath = LeadtoolsExamples.Common.ImagesPath.Path; 
 
      for(int i = 0; i < 3; i++) 
      { 
         // Load the image 
         int index = i + 1; 
         string imageFileName = imagesPath + "Image" + index.ToString() + ".cmp"; 
         RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); 
         RasterImageListItem item = new RasterImageListItem(image, 1, "Item" + index.ToString()); 
 
         // Select the first item 
         if(i == 0) 
            item.Selected = true; 
 
         // Add the item to the image list 
         imageList.Items.Add(item); 
      } 
 
      RasterCodecs.Shutdown(); 
 
      // Use manual selection 
      imageList.SelectionMode = RasterImageListSelectionMode.None; 
 
      // Add a handler to the MouseDown event 
      imageList.MouseDown += new MouseEventHandler(rasterImageList_MouseDown); 
 
      // Add the RasterImageList to the control collection. 
      Controls.Add(imageList); 
   } 
 
   private void rasterImageList_MouseDown(object sender, MouseEventArgs e) 
   { 
      RasterImageList imageList = sender as RasterImageList; 
 
      // Check if we are in manual selection mode and if this is a left button click 
      if(imageList.SelectionMode == RasterImageListSelectionMode.None && 
         e.Button == MouseButtons.Left) 
      { 
         // Yes, get the item under the cursor position 
         RasterImageListItem item = imageList.HitTest(e.X, e.Y); 
 
         // If not already selected, select this item 
         if(item != null && !item.Selected) 
         { 
            imageList.BeginUpdate(); 
 
            // First, de-select any items 
            imageList.SelectAll(false); 
 
            // Now select this item 
            item.Selected = true; 
 
            imageList.EndUpdate(); 
 
            item.Invalidate(); 
         } 
      } 
   } 

 
public void RasterImageList_SelectionMode(string title) 

   MyForm5 form = new MyForm5(title); 
   form.ShowDialog(); 
}

Remarks

If automatic item selection is enabled, items are automatically selected and de-selected when the user clicks on them using the mouse or when moving the current selected item using the keyboard.

For more information, refer to the RasterImageListSelectionMode enumeration.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also