This project is read-only.

How to Get Shapes selected by click and how select they programmatically.

Nov 11, 2013 at 3:16 PM
Hi guys, I'm new with DotSpatial,

1)If I have a layer and I click on a shape like a polygon, and so on, how get the reference of that object.
I'm looking a such property like "Layer.selectetObject" but I didn't found it.

And reversely:
2) if I have a reference of a shape how to select it on the map???

Thanks A.
Nov 14, 2013 at 2:08 PM
1) To select shapes you may use the cursor function mode select, this allows you to select all the shapes you want

programmatically you will have a button in a tool strip and pressing this button you should execute the following code:

Map1.FunctionMode = FunctionMode.Select

to get the selected features programmatically you may access to


to cycle through all the features you selected I think the code is like

foreach feature as Ifeature in yourlayer.Selection
'your code

the selection can be converted to a featureset or to a featurelist through yourlayer.Selection.ToFeatureSet and yourlayer.Selection.ToFeaturelist.
If you want to display attributes of the selected features to a datagridview (I called it DGVAttributeTable) you can write the following code
    dim dts as datatable
    dts = yourLayer.Selection.ToFeatureSet.DataTable
    DGVAttributeTable.DataSource = dts
2) to select some features programmatically you may want to use one of the following depending on how you need to choose the features to be selected:


I didn't use them so far, just try

Nov 14, 2013 at 2:49 PM
Thank you!