How to change the shapefile attribute values and their effect on the map colors

Nov 29, 2013 at 8:05 PM

how to change the attribute values of shapefile in run time and there change in color shows on map, actually i want to have a polygon shapefile and i want that the user can change the attribute values and the changes can show on map, it should represent a thematic map.

please help me if any one have any idea..

Thanks in advance.

Iftikhar Ali Mashwani
Dec 6, 2013 at 11:11 AM
Let's say your user interface has a map area, the legend with layers tree and an area with a datagridview (named DGVattributetable) on one side of the UI.

Then I would proceed in this way:
Once you load a new layer (a shapefile) let's assume you have a button that lets you show the attribute table in the datagridview (let's say this button allows you to show the attribute table of the selected map in the layer tree).

the code that this button should execute is:
        'Declare a datatable for visualization in the datagridview
        Dim dt As DataTable
        If Map1.Layers.Count > 0 Then       'Check if there are layers in your layers tree
            Dim yourLayer As FeatureLayer
            yourLayer = TryCast(Map1.Layers.SelectedLayer, FeatureLayer)
            If yourLayer Is Nothing Then
                MessageBox.Show("The layer is not a featurelayer.")
                'the code below setup a link between the datatable of your shapefile to the datagridview
                'Get the shapefile's attribute table to our datatable dt
                dt = yourLayer.DataSet.DataTable

                'Set the datagridview datasource from datatable dt
                DGVAttributeTable.DataSource = dt

            End If
            MessageBox.Show("Please add a layer to the map.")
        End If
then you can modify the values of your attribute table by changing the values in the datagridview. Once you have modified all the cells you wanted to modify you need to have a button that execute the following code (let's call it the "update" button):
           'cast again the selectedlayer to yourLayer
           Dim yourLayer As FeatureLayer
           yourLayer= TryCast(Map1.Layers.SelectedLayer, FeatureLayer)
            If yourLayerIs Nothing Then
                MessageBox.Show("The layer is not a feature layer.")
                'the following instructions are needed to update data of the datatable to the file, and to refresh the view on the screen on the basis of your simbology


            End If
This worked for me and for Joska... just try