Solved

Binding ComboBox situation, need some assistance for best practice

Posted on 2006-06-20
1
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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