none
Populate a ComboBox with data from a SharePoint List RRS feed

  • Question

  • Hi,

    I am trying to find a solution to allow a user to select a letter of the alphabet from a combobox 'cbxLetter' and depending on the value they choose I need to populate a second combobox 'cbxStations' with matching rows from a SharePoint list.

    The SharePoint List has 2600 items hence the 2 comboboxes. I have a solution to get the SharePoint List into Excel and Access but I really want to do this without any additional steps i.e. Outlook 2007 VBA directly to SharePoint 2007.

    Any help/pointers?

    Many thanks!

    Thursday, November 21, 2013 12:36 AM

Answers

  • This is what I use to get items from a project list in SP

     Private Sub GetListFromSharePoint(sProject As String)
            '*********************************************************************************************************************************************
           
    
            If CheckSPAvailable() = True Then
    
                Dim sContext As String = "http://ourextranet.mycomp.com/projects/" & sProject & "/01"
                Dim retval As Boolean = False
                Dim Context As SP.ClientContext = Nothing
                Try
                    Dim mydes As New cEncryption(cCryptHelper.K1, cCryptHelper.K2)
    
                    Dim myCredentials As NetworkCredential = New NetworkCredential(mydes.DecryptText(Globals.ThisAddIn.cInfo.GetUsername), mydes.DecryptText(Globals.ThisAddIn.cInfo.GetPassword), mydes.DecryptText(Globals.ThisAddIn.cInfo.GetDomain))
    
                    Context = New SP.ClientContext(sContext)
                    Context.Credentials = myCredentials
                    Context.AuthenticationMode = Client.ClientAuthenticationMode.Default
                    'AddHandler Context.ExecutingWebRequest, AddressOf WebRequestHandler
    
                    Dim CorList As SP.List = Context.Web.Lists.GetByTitle("Correspondence")
                    Dim CamlQCor As SP.CamlQuery = New SP.CamlQuery()
                    CamlQCor.ViewXml = "<View><RowLimit>100</RowLimit></View>"
                    Dim licCor As SP.ListItemCollection = CorList.GetItems(CamlQCor)
    
                    Context.Load(licCor)
                    Context.ExecuteQuery()
    
                    Dim frm As New frmSPDialog
                    frm.SetItems(licCor)
                    frm.ShowDialog()
    
                    Context.Dispose()
                Catch ex As SP.ClientRequestException
                    MessageBox.Show(ex.Message)
                Catch
    throw
                Finally
                    If Not IsNothing(Context) Then
                        Context.Dispose()
                    End If
                End Try
            End If

    And here is where I fill a listview from the Splist

    Public sub SetItems(Items As SP.ListItemCollection) 
            For Each Item As SP.ListItem In Items
                Dim lvitem As New ListViewItem("", 0)
    
                lvitem.SubItems.Add(Item.FieldValues("MailAttachments").ToString)
                lvitem.SubItems.Add(Item.FieldValues("Correspondence_x0020_Type"))
                lvitem.SubItems.Add(Item.FieldValues("MailSubject"))
                lvitem.SubItems.Add(Item.FieldValues("MailFrom"))
                lvitem.SubItems.Add(Item.FieldValues("MailTo"))
                lvitem.SubItems.Add(Item.FieldValues("MailDate"))
                If Not IsNothing(Item.FieldValues("MailCc")) Then
                    lvitem.SubItems.Add(Item.FieldValues("MailCc"))
                Else
                    lvitem.SubItems.Add("")
                End If
                If Not IsNothing(Item.FieldValues("Categories1")) Then
                    lvitem.SubItems.Add(Item.FieldValues("Categories1"))
                Else
                    lvitem.SubItems.Add("")
                End If
                lvitem.SubItems.Add(Item.FieldValues("Importance"))
                lvitem.SubItems.Add(Item.FieldValues("FileLeafRef"))
    
                lvItems.Items.Add(lvitem)     
            Next
    end sub



    Thursday, November 21, 2013 9:51 AM