?
Solved

Binding ComboBox situation, need some assistance for best practice

Posted on 2006-06-20
1
Medium Priority
?
188 Views
Last Modified: 2010-04-16
hello.


Lets say I have a table called Person with FirstName and PersonLastName and an ID and lets also say that I have another table called RegisteredPerson with FirstName, LastName, RegistrationNumber and ID. this is hypothetical, there are ways to design this better but that's not the point.

Okay now we have a combobox which lists everyone from Person. The list in the combobox shows their full name. We would have something like

DataAdapter adapter = new DataAdapter(
    @"SELECT ID, FirstName, LastName, TRIM(IsNull(FirstName, '') + ' ' + IsNull(LastName, '')) As 'FullName' FROM Person WHERE ID = Whatever", connection);

DataSet dsPerson = new DataSet();
adapter.Fill(dsPerson, "Person");
cmbAvailablePeople.DisplayMember = "FullName";
cmbAvailablePeople.DataSource = dsPerson.Tables["Person"];


Okay, now we would have a list of all the people in the Person table showing their first and last name concatentated. (or we should... probably syntax errors above but again this is hypothetical)

Now say the user selects a person in the combobox. Whatever person they select should now go into the RegisteredPerson table. What is the best way of doing this? We could do something like the following on the SelectedIndexChanged event, but it's kludge

cmbAvailablePeople.ValueMember = "FirstName";
tblRegisteredPeople.Rows[0]["FirstName"] = cmbAvailablePeople.SelectedValue;

cmbAvailablePeople.ValueMember = "LastName";
tblRegisteredPeople.Rows[0]["LastName"] = cmbAvailablePeople.SelectedValue;


Sure, the above works, but it seems kludge... whats the best way to handle this situation?
0
Comment
Question by:PoeticAudio
1 Comment
 
LVL 11

Accepted Solution

by:
vo1d earned 1500 total points
ID: 16945011
cmbAvailablePeople.ValueMember = "FirstName";
tblRegisteredPeople.Rows[0]["FirstName"] = cmbAvailablePeople.SelectedValue;

cmbAvailablePeople.ValueMember = "LastName";
tblRegisteredPeople.Rows[0]["LastName"] = cmbAvailablePeople.SelectedValue;

will not really work, until you add rows for that values.


why dont you make an array of boolean values with the count of persons you got in your combobox.
on selected index changed, just set the index in your array to true.
if all is finished you could insert all the rows for which the flag has been set.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question