giovedì 25 ottobre 2012

C# Google API - Load Contact's Groups ComboBox

When we insert a new contact, we need to indicate the group.
The following code shows how loading a combo box with the Contact's Groups

public void LoadGroupsComboBox()
            ContactsService _service = new ContactsService("appName");
            _service.setUserCredentials("", "yourPassword");

            GroupsQuery query = new GroupsQuery(ContactsQuery.CreateGroupsUri("default"));
            GroupsFeed feed = _service.Query(query);

            while (feed != null && feed.Entries.Count > 0)
                foreach (GroupEntry entry in feed.Entries)
                    string gruppoNome = entry.Title.Text;
                    AtomId gruppoID = entry.Id;

                    ComboboxGroup item = new ComboboxGroup();
                    item.Text = gruppoNome;
                    item.Value = gruppoID;

                                   //add the item to your combo box

                if (feed.NextChunk != null)
                    query.Uri = new Uri(feed.NextChunk);
                    feed = _service.Query(query) as GroupsFeed;
                    feed = null;


Here the definition of the class ComboboxGroup used above.

class ComboboxGroup
        public string Text { get; set; }
        public object Value { get; set; }

        public override string ToString()
            return Text;

I want to remeber to go here to get  Application-specific password

My Two Cents...

Nessun commento:

Posta un commento