PC Review


Reply
Thread Tools Rate Thread

2 dropdownlists an a problem

 
 
rodchar
Guest
Posts: n/a
 
      8th May 2009
hey all,
i have 2 dropdownlists that are the same but are different

they both have first name and last for the text values, however, in list the
names are all capitalized and shown as last name first name and in the other
list it's first name last name Proper case.

Another difference is the names have different value for the values in the
list.

is there anyway to take the text value of one list and find it in the other
list given the context?

thanks,
rodchar

 
Reply With Quote
 
 
 
 
Jeff Johnson
Guest
Posts: n/a
 
      8th May 2009
"rodchar" <(E-Mail Removed)> wrote in message
news:9133331C-120A-472B-AFE3-(E-Mail Removed)...

> i have 2 dropdownlists that are the same but are different
>
> they both have first name and last for the text values, however, in list
> the
> names are all capitalized and shown as last name first name and in the
> other
> list it's first name last name Proper case.
>
> Another difference is the names have different value for the values in the
> list.
>
> is there anyway to take the text value of one list and find it in the
> other
> list given the context?


ComboBox.FindString()


 
Reply With Quote
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      9th May 2009
In addition to Jeff's solution, if both ComboBoxes have the same datasource
you can automatically select the other item using databinding.

This code sample demonstrates how you can have a combobox displaying the
FirstName and another displaying the LastName and selecting in either
ComboBox would cause the other ComboBox to get updated (BindingSource handles
the syncronization)

public partial class Form1 : Form
{
BindingSource bs = new BindingSource();
ComboBox combo1 = new ComboBox();
ComboBox combo2 = new ComboBox();
public Form1()
{
Controls.Add(combo1);
combo2.Left = combo1.Right + 5;
Controls.Add(combo2);
}

protected override void OnLoad(EventArgs e)
{
List<Person> people = new List<Person>();
people.Add(new Person { FirstName = "Max", LastName = "Manus" });
people.Add(new Person { FirstName = "Smith", LastName =
"N'Jones" });
people.Add(new Person { FirstName = "Henry", LastName = "Rex" });

bs.DataSource = people;
combo1.DataSource = bs;
combo1.DisplayMember = "FirstName";
combo2.DataSource = bs;
combo2.DisplayMember = "LastName";
}

class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}

I suspect you have something like a list of Person in one ComboBox and a
list of Employee in another. They might be the same people but their names
are displayed differently and the lists are different (ie may not have
exactly the same peole). In that case, if you can figure out how the name is
displayed in the other ComboBox you can use FindString like Jeff pointed out.
The best solution would be to do it behind the scenes using a unique
identifier between the list, like a social security number. This would
support cases where you have two people with the same name.

--
Happy Coding!
Morten Wennevik [C# MVP]


"rodchar" wrote:

> hey all,
> i have 2 dropdownlists that are the same but are different
>
> they both have first name and last for the text values, however, in list the
> names are all capitalized and shown as last name first name and in the other
> list it's first name last name Proper case.
>
> Another difference is the names have different value for the values in the
> list.
>
> is there anyway to take the text value of one list and find it in the other
> list given the context?
>
> thanks,
> rodchar
>

 
Reply With Quote
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      9th May 2009
In addition to Jeff's solution, if both ComboBoxes have the same datasource
you can automatically select the other item using databinding.

This code sample demonstrates how you can have a combobox displaying the
FirstName and another displaying the LastName and selecting in either
ComboBox would cause the other ComboBox to get updated (BindingSource handles
the syncronization)

public partial class Form1 : Form
{
BindingSource bs = new BindingSource();
ComboBox combo1 = new ComboBox();
ComboBox combo2 = new ComboBox();
public Form1()
{
Controls.Add(combo1);
combo2.Left = combo1.Right + 5;
Controls.Add(combo2);
}

protected override void OnLoad(EventArgs e)
{
List<Person> people = new List<Person>();
people.Add(new Person { FirstName = "Max", LastName = "Manus" });
people.Add(new Person { FirstName = "Smith", LastName =
"N'Jones" });
people.Add(new Person { FirstName = "Henry", LastName = "Rex" });

bs.DataSource = people;
combo1.DataSource = bs;
combo1.DisplayMember = "FirstName";
combo2.DataSource = bs;
combo2.DisplayMember = "LastName";
}

class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}

I suspect you have something like a list of Person in one ComboBox and a
list of Employee in another. They might be the same people but their names
are displayed differently and the lists are different (ie may not have
exactly the same peole). In that case, if you can figure out how the name is
displayed in the other ComboBox you can use FindString like Jeff pointed out.
The best solution would be to do it behind the scenes using a unique
identifier between the list, like a social security number. This would
support cases where you have two people with the same name.

--
Happy Coding!
Morten Wennevik [C# MVP]


"rodchar" wrote:

> hey all,
> i have 2 dropdownlists that are the same but are different
>
> they both have first name and last for the text values, however, in list the
> names are all capitalized and shown as last name first name and in the other
> list it's first name last name Proper case.
>
> Another difference is the names have different value for the values in the
> list.
>
> is there anyway to take the text value of one list and find it in the other
> list given the context?
>
> thanks,
> rodchar
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with dropdownlists in gridview Mark Microsoft ASP .NET 2 30th Jul 2007 11:55 PM
Strange problem with SelectedIndex property affecting multiple dropdownlists RSH Microsoft ASP .NET 3 8th Feb 2007 07:13 PM
Problem with DropDownLists and Post Backs ~john Microsoft ASP .NET 5 19th Dec 2006 04:21 PM
Newbie problem with 2 dropdownlists to fill gridview Wouter Microsoft ASP .NET 0 29th Nov 2006 04:19 PM
Problem with FormView and DropDownLists =?Utf-8?B?QmFzIFBhYXA=?= Microsoft ASP .NET 3 11th Apr 2006 02:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.