How to get List Items in ListView


This Code Helps you to get the List items in List View Control…… use both these functions…. first function will populate the List Fields and Second will get the List Field Values……
 
 

Public Sub GetListHeaders(ByVal caller As Uri) ‘—This Function Gets All Field Titles and Make them Columns of ListView —‘

spsite =

New SPSite(caller.ToString)

childexplorer.LvListItems.Items.Clear()

childexplorer.LvListItems.Columns.Clear()

Try

Dim splist As SPList

splist = spsite.OpenWeb.Lists(childexplorer.TvSites.SelectedNode.Text)

For Each SPField As SPField In splist.Fields ‘ —Get All Fields —‘

If (SPField.Title <> "Edit") Then

childexplorer.LvListItems.Columns.Add(SPField.Title.ToString)

End If

Next

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub

 
 
 
 
Public Sub GetListItems(ByVal caller As Uri) ‘—This Function Gets Items of Selected List —‘

Tryim FieldCount As Integer = 0

Dim i As Integer = 1

Dim ListItemIndex As Integer = 0

Dim SpList As SPList

Dim SelectedListItem As String = ""

SelectedListItem = childexplorer.TvSites.SelectedNode.Text.ToString

childexplorer.LvListItems.Items.Clear()

spsite =

New SPSite(caller.ToString)

SpList = spsite.OpenWeb.Lists(childexplorer.TvSites.SelectedNode.Text)

If (SpList.Items.Count > 0) Then

For Each splistitem As SPListItem In SpList.Items

childexplorer.LvListItems.Items.Add(splistitem.Item(0).ToString)

Next

Else

MessageBox.Show("No List item in " + SpList.Title.ToString, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

Select Case SelectedListItem

Case "My Discussion Board"

For Each item As ListViewItem In childexplorer.LvListItems.Items

ListItemIndex = item.Index

FieldCount = SpList.Fields.Count

If (SpList.Items.Count > 0) Then

For Each splistitem As SPListItem In SpList.Items

If (splistitem(0) = item.Text) Then

For i = 1 To FieldCount – 3

If (splistitem.Item(i) <> Nothing) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(splistitem(i).ToString)

ElseIf (splistitem.Item(i) = True) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(

"True")

ElseIf (splistitem.Item(i) = Nothing) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add("NULL")

ElseIf (splistitem.Item(i) = False) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(

"False")

End If

Next

End If

Next

End If

Next

Case Else

For Each item As ListViewItem In childexplorer.LvListItems.Items

ListItemIndex = item.Index

FieldCount = SpList.Fields.Count

If (SpList.Items.Count > 0) Then

For Each splistitem As SPListItem In SpList.Items

If (splistitem(0) = item.Text) Then

For i = 1 To FieldCount – 2

If (splistitem.Item(i) <> Nothing) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(splistitem(i).ToString)

ElseIf (splistitem.Item(i) = True) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(

"True")

ElseIf (splistitem.Item(i) = Nothing) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(

"NULL")

ElseIf (splistitem.Item(i) = False) Then

childexplorer.LvListItems.Items(ListItemIndex).SubItems.Add(

"False")

End If

Next

End If

Next

End If

Next

End Select

Catch ex As Exception

MsgBox(ex.Message.ToString)

End Try

End Sub

Advertisements

2 Comments

  1. Having read this I believed it was very informative.

    I appreciate you spending some time and effort to put this information together.
    I once again find myself personally spending a
    significant amount of time both reading and leaving comments.

    But so what, it was still worth it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: