Populating ListView From shapefile

692
2
Jump to solution
05-01-2013 12:01 AM
HushamHassan
Occasional Contributor
Hi, 
I have a listview in  my form I need to populate with the selected feature record,  my code fill all the field in one columns, I need to show only 5 columns in my listview.  here is my code so far.

Dim nCols As Integer              nCols = pFeature.Fields.FieldCount              For i = 2 To nCols - 1                  Me.Listsheet.Items.Add(pFeature.Fields.Field(i).Name)                 Me.Listsheet.Items.Add(pFeature.Value(i))               Next

Regards
0 Kudos
1 Solution

Accepted Solutions
BarbaraSchneider1
New Contributor III
Hi,

first you have do define the header for your listView:

For i = 0 To pFeature.Fields.FieldCount - 1     strFieldname = pFeature.Fields.Field(i).Name     pColHeader = New ColumnHeader()     pColHeader.Text = strFieldname     Me.Listsheet.Columns.Add(pColHeader) Next


Then you can add the items and the subitems. The error you made is that you only filled in the items (these only fill the first column). To fill in the subsequent columns, you need to add subitems:

Dim pListItem As ListViewItem  pListItem = Me.Listsheet.Items.Add(pFeature.Value(0)) ' fill in value in first column For i = 1 To pFeature.Fields.FieldCount - 1     pListItem.SubItems.Add(pFeature.Value(i))         ' fill in values in all remaining columns     Next


I hope this helps.

Kind regards,
Barbara

View solution in original post

0 Kudos
2 Replies
BarbaraSchneider1
New Contributor III
Hi,

first you have do define the header for your listView:

For i = 0 To pFeature.Fields.FieldCount - 1     strFieldname = pFeature.Fields.Field(i).Name     pColHeader = New ColumnHeader()     pColHeader.Text = strFieldname     Me.Listsheet.Columns.Add(pColHeader) Next


Then you can add the items and the subitems. The error you made is that you only filled in the items (these only fill the first column). To fill in the subsequent columns, you need to add subitems:

Dim pListItem As ListViewItem  pListItem = Me.Listsheet.Items.Add(pFeature.Value(0)) ' fill in value in first column For i = 1 To pFeature.Fields.FieldCount - 1     pListItem.SubItems.Add(pFeature.Value(i))         ' fill in values in all remaining columns     Next


I hope this helps.

Kind regards,
Barbara
0 Kudos
HushamHassan
Occasional Contributor
hi Barbara
Thank you for your help Your code worked fine after little modification.
Here is the working Code for me.

Dim pColHeader As ColumnHeader
            Dim strFieldname As String
            For j = 0 To pFeature.Fields.FieldCount - 1
                strFieldname = pFeature.Fields.Field(j).Name
                pColHeader = New ColumnHeader()
                pColHeader.Text = strFieldname
                Me.Listsheet.Columns.Add(pColHeader)
            Next

            Dim pListItem As New ListViewItem

            pListItem = Me.Listsheet.Items.Add(pFeature.Value(0)) ' fill in value in first column
            For i = 1 To (pFeature.Fields.FieldCount - 1)
                ' pListItem.SubItems.Add(CStr(pFeature.Value(i)))       ' fill in values in all remaining columns    
                pListItem.Text = Convert.ToString(pFeature.Value(i))
                pListItem.SubItems.Add(Convert.ToString(pFeature.Value(i)))
            Next


Regards
0 Kudos