Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Get corresponding column value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RP - 16 Oct 2007 09:37 GMT
I have a combo box and I am filling Employee Codes in it. I want to
retrieve employee first and last name when a user selects an employee
code from the combo box. Though it very easy with a single SQL Query,
I want to know if there is any other way to get this. I mean if I use
following query:

Select EmpCode, FirstName, LastName from <Table Name>

and use column(o) to fill the combo box. Can I store other values as
well in combo box to retrieve them when the user selects a code.
bob - 16 Oct 2007 10:52 GMT
Hi,
You can create an employee class and fill the combo box with a set of
those.
if you overwrite the ToString() method so that it returns EmpCode then
the combox box will show that.

Use the Selected indexed changed event to get the selected item which
can be cast as an employee (if it is not already, I cant remember) and
all its properties accessed.
hth
bob

>I have a combo box and I am filling Employee Codes in it. I want to
>retrieve employee first and last name when a user selects an employee
[quoted text clipped - 6 lines]
>and use column(o) to fill the combo box. Can I store other values as
>well in combo box to retrieve them when the user selects a code.
Vadym Stetsiak - 16 Oct 2007 10:58 GMT
Hello, RP!

If you're talking about WinForms application - combobox control has Tag
property. This property can be used to store arbitrary data.

If employee's select resultset is not large, you can cache employee data
into a data structure ( dictionary with employee code as key) and put that
data structure
into control's Tag property. When user selects value from combobox you'll
perfrom search in the attached dictionary to retrieve Emp data.

OTOH if employee's select results set can be large enough other strategies
of data retrieval  have to come into play.

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote  on Tue, 16 Oct 2007 08:37:57 -0000:

R> I have a combo box and I am filling Employee Codes in it. I want to
R> retrieve employee first and last name when a user selects an employee
R> code from the combo box. Though it very easy with a single SQL Query,
R> I want to know if there is any other way to get this. I mean if I use
R> following query:

R> Select EmpCode, FirstName, LastName from <Table Name>

R> and use column(o) to fill the combo box. Can I store other values as
R> well in combo box to retrieve them when the user selects a code.
Chris Shepherd - 16 Oct 2007 13:34 GMT
> I have a combo box and I am filling Employee Codes in it. I want to
> retrieve employee first and last name when a user selects an employee
[quoted text clipped - 6 lines]
> and use column(o) to fill the combo box. Can I store other values as
> well in combo box to retrieve them when the user selects a code.

Yes you can. If it's databound it's pretty easy:

comboBox1.DataSource = dt;
comboBox1.DisplayMember = "EmpCode";
comboBox1.ValueMember = "EmpCode";

Then you can extract the DataRow/DataRowView (by default if you bind it,
it's a DataRowView) from the combobox like:

DataRowView row = (DataRowView)comboBox1.SelectedItem;
MessageBox.Show(row["EmpCode"].ToString() + ": " +                            
row["FirstName"].ToString() + " " +
        row["LastName"].ToString());

If it's your own custom object, it's pretty much the same. SelectedItem
would be whatever you added via a data binding process or via the
comboBox1.Items.Add() method.

Chris.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.