-
How to bind 2 fields into 1 combobox
Hi,
I need advice and help. I am trying to display 2 fields as a choice in 1 combobox. I only know how to display 1 field in the combobox.
I am currently working with this code.
CustomerSupplierIDComboBox.DataSource = E2_PRODataSet.Tables("CUSTOMER")
CustomerSupplierIDComboBox.DisplayMember = "CustomerID"
CustomerSupplierLabel.DataBindings.Add("Text" CUSTOMERBindingSource, "CustomerName")
My next table to be include in this combobox is the SUPPLIER Table with the label to be display is SupplierName. How do I include all this to operate the combobox?
Please advice.
-
I would suggest two things:
1. If you want more than one field don't use data binding. Populate your control through programming code over you which you will have more control.
2. If you want more than one field switch to something like a grid or a Listview.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
You could generate a dataset that does a UNION between the two tables and use that as your datasource.
...joe
-
But still, Joe, wouldn't you agree that storing more than column of data in a garden variety combo box is not the best design idea?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
I agree 100%. It makes more sense from a design standpoint to use a customer and a supplier combobox.
...joe
-
-
You could append two columns. for eg. if you have to display empolyer Id and employer name in the combobox you could add the lineItem like
'1 - ABC Corp'. So you end up getting two columns seperated by a '-'
-
But, that is still a single string, not two separate strings. To get the Id or get the name, you would need to parse it. It is much simpler to simply use a control that supports columns.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
I know this is pretty much a dead thread, but it isn't really answered. So here's an idea for anyone looking at this trying to find answers. You could always make an extra column with a concatenation of the ID and Customer Name. I'm not sure how to code that, but if you don't mind using a dataset.designer go and add a column. Under the new column's properties, go to expression. Enter:
[CustomerID] + ' ' + [CustomerName]
into the expression field and you now have a field to pull into your combobox to show both, the customer id and customer name as the display member. Remember to set your value member as either the customer id or the customer name to put off the value you are wanting. You can't use you concatenated field for the value.
-
But still, in order to get the Id or get the name, you would need to parse it as it is still one string.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
hi there,
this solution is already mentioned.
in the select statement used to populate your combobox, you should concatenate your two columns into one column, and then use this concatenated column to display in your comboxbox.
so, you have two columns col1 and col2, your sql statement should look like this:
select t1.col1 + ' ' + t2.col2 as concatenated_column
from table1 t1, table2 t2
where...
for your combobox, you would use your "concatenated_column".
that's it,
tonci korsano
-
 Originally Posted by tkorsano
hi there,
this solution is already mentioned.
in the select statement used to populate your combobox, you should concatenate your two columns into one column, and then use this concatenated column to display in your comboxbox.
so, you have two columns col1 and col2, your sql statement should look like this:
select t1.col1 + ' ' + t2.col2 as concatenated_column
from table1 t1, table2 t2
where...
for your combobox, you would use your "concatenated_column".
that's it,
tonci korsano
Yes, I agree with you, that's right!
-
-
// this will create a combo box with two columns.
dtDataTable = getDataTable();
foreach (DataRow dr in dtDataTable.Rows)
{
sId = dr["id"].ToString ();
sDesc = dr["description"].ToString();
cboBox.Items.Add(sId + " - " + sDesc);
}
-
As we know Combo Box control can only display one column(field) with the data source, it's not support by combo box that display multi column connections like field1-field2 when it is data binded. Although this cannot be done directly, we can do it indirectly by using Format event of the Combo Box. The Format event is raised before each visible item is formatted.
http://www.dapfor.com/en/net-suite/n...l/data-binding
Similar Threads
-
By diana_j86 in forum .NET
Replies: 5
Last Post: 04-06-2009, 01:46 PM
-
By subrama6 in forum .NET
Replies: 4
Last Post: 02-13-2008, 09:19 AM
-
Replies: 1
Last Post: 06-19-2005, 05:09 PM
-
By Stan Shankman in forum .NET
Replies: 2
Last Post: 09-07-2001, 03:06 AM
-
By Karel Semerák in forum VB Classic
Replies: 1
Last Post: 03-27-2000, 07:22 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks