Solved

Binding ComboBox situation, need some assistance for best practice

Posted on 2006-06-20
1
185 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

719 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