multiselect shapes

Jun 11, 2012 at 6:26 AM

Hi all,

 

I'm trying to figure out how to select multiple shapes using the Ctrl key, but I get stuck. Is there any information on this? I'm using the code below which works fine for selecting one shape, but I would like to be able to select two or more countries (not necessarily neighbours) on the world map.

Can anyone help me on this please?

Many thanks

 

Private Sub AxMap1_MouseDownEvent(sender As System.Object, e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
        
        Dim ext As New MapWinGIS.Extents
        Dim TL, BR As MapWinGIS.Point
        Dim shapes As Object
        Dim shp As Integer
        Dim i As Integer
        Dim shpIndex As Long

        hndWorld = AxMap1.AddLayer(sfWorld, True)

        Dim index As Integer
        index = sfWorld.Table.FieldIndexByName("UN")
        sfWorld.Categories.Generate(index, MapWinGIS.tkClassificationType.ctUniqueValues, 0)
        sfWorld.Categories.ApplyExpressions()

        TL = New MapWinGIS.Point 'Top Left Projected
        BR = New MapWinGIS.Point 'Bottom Right Projected

        AxMap1.PixelToProj(e.x, e.y, TL.x, TL.y)
        AxMap1.PixelToProj(e.x, e.y, BR.x, BR.y)
        ext = New MapWinGIS.Extents
        ext.SetBounds(TL.x, BR.y, 0, BR.x, TL.y, 0)
        If Not sfWorld.SelectShapes(ext, 0.0, MapWinGIS.SelectMode.INTERSECTION, shapes) = False Then

            For shp = 0 To shapes.GetUpperBound(0)

                shpIndex = sfWorld.ShapeCategory(shapes(i))
                sfWorld.Categories.Item(shpIndex).DrawingOptions.FillColor = RGB(255, 255, 0)

                TextBox1.Text = (sfWorld.CellValue(4, shapes(i)))

            Next shp
        End If
    End Sub

Jun 11, 2012 at 8:42 AM

OK, perhaps not the most elegant solution, but I found something that works. Each time a country is selected and the Shift key is pressed, its shpIndex is added to a listbox and all shapes from the listbox are subsequently selected (and coloured). I tried with a list array but each time a country is clicked the array is emptied so that didn't work. Of course if someone has a better solution please let me know!

 

 If Not sfWorld.SelectShapes(ext, 0.0, MapWinGIS.SelectMode.INTERSECTION, shapes) = False Then

            For shp = 0 To shapes.GetUpperBound(0)
                shpIndex = sfWorld.ShapeCategory(shapes(i))
                If e.shift Then
                    ListBox1.Items.Add(shpIndex)
                End If
            Next shp
            For i = 0 To ListBox1.Items.Count - 1
                shpIndex = ListBox1.Items(i)
                sfWorld.Categories.Item(shpIndex).DrawingOptions.FillColor = RGB(255, 255, 0)
            Next
        End If