This project is read-only.

How to retrieve all fieldnames of a shape into a combobox..?

Sep 15, 2012 at 2:28 AM

Hello readers 

I tried a dozen of examples and test but somehow i failed to solve this,

how can I retrieve all names of the fields in a table of the shape.... to fill a combobox....?

plzzz help, tx in advance

 

Sep 15, 2012 at 6:01 PM
Edited Sep 15, 2012 at 6:16 PM

Well to keep u updated, I found a possible solution at the 7th tutorial doc 

Shape file label operations~ Tutorial (7)

 

I used the code and did the NET4.0 instruction, but this isnt working yet, it generates 2 errors, one in each sub.... 1) Access..... through qualifying expression will not be evaluated AND 2) data is not a member of Dotspatial.Data.Featureset.... 

Any ideas to give me some direction......... i will first try to solve the 2nd one.....

 

 Private Sub CheckedListBoxGEBOUWENshape_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBoxGEBOUWENshape.SelectedIndexChanged

        'Clear the existing layers from the map control
        If (myVenster.Layers.Count > 0) Then
            myVenster.Layers.Clear()
        End If
        'Clear the exisiting items from the combobox
        ComboBoxAdressenAttributen.Items.Clear()

        Dim fileDialog As New OpenFileDialog()
        FileDialog.Filter = "Shapefiles|*.shp"
        If fileDialog.ShowDialog = DialogResult.OK Then
            'add layer to first map

            Dim featureSet1 As New FeatureSet
            featureSet1.Open(fileDialog.FileName)

            'FillColumnNames method is used to get all the attribute column names 
            'Based on the names combobox will be populated
            Fillcolumnnames(featureSet1)
            featureSet1.Reproject(myVenster.Projection)
            myVenster.Layers.Add(featureSet1)
            myVenster.ZoomToMaxExtent()
        End If
    End Sub

    Private Sub FillColumnNames(ByVal ByValfeatureSet As IFeatureSet)
        For Each column As DataColumn In FeatureSet.DataTable.Columns
            cmbFiledName.Items.Add(column.ColumnName)
        Next
    End Sub
Sep 16, 2012 at 11:25 AM

Hello,joska.   I have faced the same problem,you said you have found a possible solution at the 7th tutorial.doc

But I can't find it on the Website of Dotspatial,so can you sent me the 7th tutorial.doc,I'm trying to solve this problem.

My Email: 524738928@qq.com        Thank you very much.      

Sep 16, 2012 at 2:22 PM

hi devils...   here it is, scroll down.... u see a little table   it consists some tutorials  who are sadly out of date.....

I hope you can find the solution    im sure its simple but i cannot solve it yet.....

http://dotspatial.codeplex.com/wikipage?title=DotSpatial%20Tutorials&referringTitle=Documentation

Sep 18, 2012 at 3:01 AM
Hello, Joska.The code from the tutorials works correct in my program.But I'm using the C# not VB ,I don't if it can help you.
IFeatureSet fs = new FeatureSet();
fs.Projection = KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld;
fs = FeatureSet.Open(fileInfo.FullName);
fs.FillAttributes(); 
foreach (DataColumn column in fs.DataTable.Columns)
{
this.comboBox2.Items.Add(column.ColumnName);
}

 

 

Sep 18, 2012 at 3:06 AM
Edited Sep 18, 2012 at 4:04 AM
thanx devils i will check right away
i hope not vb is teh problem here, check this small sample and read my comment..... even if change it it wont work (yet)
can u try the C# equivalent in your software to see whats more wrong?
i think it contains teh same error but even if you correct it will it work?
thx anyway Devils!!
Joska


Sep 18, 2012 at 3:13 AM
Thanx devils.... it works it must be something to do with the Ifeatureset

any idea what it does in special over the original code....?


From: [email removed]
To: [email removed]
Date: Mon, 17 Sep 2012 19:01:34 -0700
Subject: Re: How to retrieve all fieldnames of a shape into a combobox..? [DotSpatial:395620]

From: Devils
Hello, Joska.The code from the tutorials works correct in my program.But I'm using the C# not VB ,I don't if it can help you.
IFeatureSet fs = new FeatureSet();
fs.Projection = KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld;
fs = FeatureSet.Open(fileInfo.FullName);
fs.FillAttributes(); 
foreach (DataColumn column in fs.DataTable.Columns)
{
this.comboBox2.Items.Add(column.ColumnName);
}



Read the full discussion online.
To add a post to this discussion, reply to this email (DotSpatial@discussions.codeplex.com)
To start a new discussion for this project, email DotSpatial@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Sep 19, 2012 at 6:11 PM

I sorry to reply to you so late as I'm a little busy those days.

The sample code from http://dotspatial.codeplex.com/wikipage?title=TableSingleCS&referringTitle=Desktop_SampleCode works correct, this method is a part of my appolication,

and I can get the value form the field. The code is as follow

                DataTable dt = fs.DataTable;
                Featurecount = fs.Features.Count;
                for (int i = 0; i < fs.Features.Count; i++)
                {
                    IFeature ft = fs.GetFeature(i);
                    pointxy[i, 0] = ft.Centroid().Envelope.X;
                    pointxy[i, 1] = ft.Centroid().Envelope.Y;
                    score[i] = Convert.ToDouble(dt.Rows[i][this.comboBox2.Text]);
                    Sum += score[i];
                }
I don't if there are some problem with the VB. Hope you can solve it soon. Good luck!  

 

Sep 19, 2012 at 6:15 PM

thx devil   this part is already working in my programm   and it works fine.....  

may i ask if u:

- have the toolbox with GIS functionalities working in one of your programms?

- any code how to colorsheme like say buildingsheights?   i simply an not find good samples how to make a simple filter for lets say coloring heigth of buildings and have it appear in the legend....

thx again for appearing here :o)