Solved

Binding ComboBox situation, need some assistance for best practice

Posted on 2006-06-20
1
178 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 500 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 run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now