Reputation: 197
private void abi3_Click(object sender, EventArgs e)//gonder
{
foreach (var item in ContactResultsData.SelectedItems)
{
Contacts cons = new Contacts();
cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs> (Con_SearchCompleted);
cons.SearchAsync(item.ToString(), FilterKind.DisplayName, null);
}
}
void Con_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
foreach (var contact in e.Results)
{
if (contact.PhoneNumbers.Count() > 0)
{
textBox1.Text = textBox1.Text + ";" + contact.PhoneNumbers.FirstOrDefault();
}
}
I am using this code for get phone numbers of my contacts. I have a listview and all contacts are in it. then I multi select and show the names and phones.
but for example, one of my contact name is "alex". the other is "alex de sousa". when I select "alex" and "alex de sousa", this program gets just alex's number twice. no show the alex de soousa's number.
how can I solve this problem. Thanks
Upvotes: 0
Views: 131
Reputation: 69372
To answer the updated question from the comments, you can check to see if the contact's DisplayName
exactly matches the search query.
Pass in the query as the object's state like this
cons.SearchAsync(item.ToString(), FilterKind.DisplayName, item.ToString());
Then read the state in the SearchCompleted
event and see if it's an exact match like this
if (contact.PhoneNumbers.Count() > 0 && String.Equals(contact.DisplayName, e.State.ToString()))
Upvotes: 1