Lookup Contacts using a listbox

Discussion in 'Questions (Windows Mobile)' started by thartung, Feb 25, 2008.

  1. thartung

    thartung New Member Licensed User

    :sign0104:
    I am trying to learn how to create a listbox that is populated by the PIM contacts, and being a noob, I am a bit confused. I have found some examples that show how to add the contacts collection and so forth, but I am not sure how to extact the selected item in the list. So far this is what I have:

    form2.show
    sendlist.New1
    ContactsCollection.New1("Contacts")
    ContactsCollection.SortItems("LastName",false) 'sorts the contacts using the last name field.
    For i = 0 To ContactsCollection.Count - 1
    Contact.Value = ContactsCollection.GetItem(i)
    listbox1.Add(Contact.LastName & " " & Contact.firstName) 'Add the contact's first and last name to ListBox1.
    Next
    Contact.Value = ContactsCollection.GetItem(listbox1.SelectedIndex)

    It errors out on the last line. Error says object reference not set

    Thank you for any help provided:confused:
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What is sendlist?
    Did you add the ContactsCollection object and the Contact object (with Tools - Add Object)?
    You are also missing Contact.New1 in the beginning.
     
  3. RandomCoder

    RandomCoder Well-Known Member Licensed User

    This might help, I did it for someone else asking a very similar question.
    It only shows contacts that have a mobile number listed.
    Modify it to your own needs,

    PS don't forget to add the Outlook.dll's to the working directory.

    Regards,
    RandomCoder
     

    Attached Files:

  4. thartung

    thartung New Member Licensed User

    Thank you for the code. I loaded it on my device making sure the outlook.dll was in the working directory. When I run it on my device the listbox "Select Name" and "Mobile Number" are blank. No errors, but I would have expected to see a list of my contacts with a mobile number. I realize when running on the desktop they would be blank because of the "dummy" dll, but shouldn't I see something on the device?:confused:
     
  5. thartung

    thartung New Member Licensed User

    I just thought..... I have basic4PPC and all my sample code on my storage card. Could this be a problem?? I have been able to successfully run other samples
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that the storage card is the problem.
    Please try the attached example.
     

    Attached Files:

  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I'm sorry to hear that you had problems with the code.
    Is it possible that you have a blank entry within your contacts?
    Because the listbox is set to a height of only one entry, it may be that the box is populated but just showing the blank entry, try scrolling down.
    As it didn't error I would guess that it is working, you could also try making the listbox larger.

    Regards,
    RandomCoder
     
  8. thartung

    thartung New Member Licensed User

    Thank you for the code Erel. This snippet works, yet the example that RandomCoder provided still doesn't seem to show any contacts even after I made the listbox larger. Not a big deal. I appreciate the time both of you spent helping me.

    Thanks again!!
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    RandomCoder's example shows only contacts which have a MobilePhoneNumber.
    I've changed his example to show all contacts.
     
  10. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Sorry for the confusion caused, but I did state that it selects only contacts having a mobile number.
    If loading all contacts regardless of the contact details then there is no need to keep track of the index as this will be unaltered.

    Regards,
    RandomCoder
     
Loading...