Select to view content in your preferred language

How to show selected features in a DataGridView (VB.net or C#)

3141
2
07-10-2015 07:56 AM
JoseSanchez
Regular Contributor

Hello everyone,

Any sample showing how to show all the selected features from a feature class in a map in a  DataGridView.

I am building an add-in for that.

Will you use a dockable window or a regular window?

Thanks

0 Kudos
2 Replies
ChrisSmith7
Frequent Contributor

Jose,

Is using DataGridView in .NET a definite requirement? If not, and you're using the JS API, check out Using FeatureTable | ArcGIS API for JavaScript

I am using the JS API on a site with a vb.net back-end... Not sure if you are in a similar scenario - by add-in, are you referring to extending ArcGIS Desktop? If so, you can disregard my suggestion! Looks like Ken has a solution for that.

0 Kudos
KenBuja
MVP Esteemed Contributor

In one app, I used a DataGridView (dgvMPAs) to hold features. I didn't show all the attributes of the features in the table, just a selection of them. I also added a check box into each row.

pFCursor = pMPAFClass.Search(Nothing, False)
pFeature = pFCursor.NextFeature

Dim dgvRow As System.Windows.Forms.DataGridViewRow
Dim dgvCell As System.Windows.Forms.DataGridViewCell
Dim NameIndex As Integer = pMPAFClass.FindField("SITE_NAME")
Dim IDIndex As Integer = pMPAFClass.FindField("SITE_ID")

Do While Not pFeature Is Nothing
    dgvRow = New System.Windows.Forms.DataGridViewRow
    dgvCell = New System.Windows.Forms.DataGridViewCheckBoxCell
    dgvRow.Cells.Add(dgvCell)

    dgvCell = New System.Windows.Forms.DataGridViewTextBoxCell
    dgvCell.Value = pFeature.OID
    dgvRow.Cells.Add(dgvCell)

    dgvCell = New System.Windows.Forms.DataGridViewTextBoxCell
    dgvCell.Value = pFeature.Value(IDIndex)
    dgvRow.Cells.Add(dgvCell)

    dgvCell = New System.Windows.Forms.DataGridViewTextBoxCell
    dgvCell.Value = pFeature.Value(NameIndex)
    dgvRow.Cells.Add(dgvCell)

    dgvMPAs.Rows.Add(dgvRow)

    pFeature = pFCursor.NextFeature
Loop

In the form, I set up the DataGridView with four columns, with the OID field's visibility set to false. The user didn't need to see it, but I used it when doing a search on the selected records (selected by the check box) later.

DataGridView.png

0 Kudos