PC Review


Reply
Thread Tools Rate Thread

DisplayMember / ValueMember Question

 
 
James
Guest
Posts: n/a
 
      28th Feb 2004
HERE'S THE SHORT VERSION OF MY QUESTION:
When using the DisplayMemeber property of a combobox, is it possible
to concatenate multiple fields from a dataview for use as the value to
display, or do you have to handle the concatenation in the dataset?

HERE'S THE IN-DEPTH DESC OF WHAT I'M TRYING TO DO:
I'm writing a Smart Device solution that reads data from an XML
datasource into a dataset, then I break-out the tables into dataviews
for to bind to my form's controls.

One of the tables in my dataset is a table that contains information
about a car, such as Make, Model, Year, etc. The Car table has a
PrimaryKey called car_id.

I have a combo box that let's the user select a car and see detailed
information about the car in a datagrid. The combobox is fed from a
dataview called dvCars and the datagrid is bound to a dataview called
dvCarDetails. I use the DisplayMember and ValueMember properties of
the combobox to store the Make of the vehicle and then the vehicle ID
respectively. When the combo's index changes, the filter for the
datagrid's dataview is changed to match the selected vehicle using the
car_id stored in the ValueMember of the combo.

Given that Year, Make nor Model alone is really descriptive enough for
a user to choose from the selection of cars, is it possible
concatenate all three (Year, Make & Model) so the concatenated value
is used as the DisplayMember to help the user choose more accurately?
I still need to store car_id in ValueMember though, to filter my Car
Details dataview.

For reference, here's my code:

Private Sub PopulateCmbVehicles()
Dim VehicleCount, x As Integer
Dim strVehicleDesc As String

Me.dvCars.RowFilter = "active = 'Y'"

Me.cmbVehicles.DataSource = Me.dvCars
cmbVehicles.ValueMember = "car_id"
cmbVehicles.DisplayMember = "make"
End Sub


Private Sub PopulateDG1()
Dim strFilter As String
Dim row As DataRowView = CType(cmbVehicles.Items
_(cmbVehicles.SelectedIndex), DataRowView)

strFilter = "car_id = '" & row("car_id") & "'"
Me.dvCarDetails.RowFilter = strFilter
Me.DG1.DataSource = dvCarDetails

End Sub

Thanks much!
Jamie
 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      28th Feb 2004
You'll need to have the values already concatenated to do this as the
ComboBox can only be bound to a single value and single display column. You
can create an Expression column in your dataset to combine the values of
several other fields.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"James" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> HERE'S THE SHORT VERSION OF MY QUESTION:
> When using the DisplayMemeber property of a combobox, is it possible
> to concatenate multiple fields from a dataview for use as the value to
> display, or do you have to handle the concatenation in the dataset?
>
> HERE'S THE IN-DEPTH DESC OF WHAT I'M TRYING TO DO:
> I'm writing a Smart Device solution that reads data from an XML
> datasource into a dataset, then I break-out the tables into dataviews
> for to bind to my form's controls.
>
> One of the tables in my dataset is a table that contains information
> about a car, such as Make, Model, Year, etc. The Car table has a
> PrimaryKey called car_id.
>
> I have a combo box that let's the user select a car and see detailed
> information about the car in a datagrid. The combobox is fed from a
> dataview called dvCars and the datagrid is bound to a dataview called
> dvCarDetails. I use the DisplayMember and ValueMember properties of
> the combobox to store the Make of the vehicle and then the vehicle ID
> respectively. When the combo's index changes, the filter for the
> datagrid's dataview is changed to match the selected vehicle using the
> car_id stored in the ValueMember of the combo.
>
> Given that Year, Make nor Model alone is really descriptive enough for
> a user to choose from the selection of cars, is it possible
> concatenate all three (Year, Make & Model) so the concatenated value
> is used as the DisplayMember to help the user choose more accurately?
> I still need to store car_id in ValueMember though, to filter my Car
> Details dataview.
>
> For reference, here's my code:
>
> Private Sub PopulateCmbVehicles()
> Dim VehicleCount, x As Integer
> Dim strVehicleDesc As String
>
> Me.dvCars.RowFilter = "active = 'Y'"
>
> Me.cmbVehicles.DataSource = Me.dvCars
> cmbVehicles.ValueMember = "car_id"
> cmbVehicles.DisplayMember = "make"
> End Sub
>
>
> Private Sub PopulateDG1()
> Dim strFilter As String
> Dim row As DataRowView = CType(cmbVehicles.Items
> _(cmbVehicles.SelectedIndex), DataRowView)
>
> strFilter = "car_id = '" & row("car_id") & "'"
> Me.dvCarDetails.RowFilter = strFilter
> Me.DG1.DataSource = dvCarDetails
>
> End Sub
>
> Thanks much!
> Jamie



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
listbox displaymember & valuemember Henry Jones Microsoft VB .NET 3 11th Jul 2006 11:59 AM
proposedValue contains displayMember instead of valueMember =?Utf-8?B?TWFya3VzIEhpbGY=?= Microsoft VB .NET 1 31st Mar 2005 11:05 AM
Valuemember/Displaymember vs. Delegates cody Microsoft Dot NET 3 2nd Mar 2005 04:41 PM
ComboBox / DisplayMember & ValueMember Brian Mitchell Microsoft VB .NET 1 14th Mar 2004 02:20 AM
Combo Box Displaymember, Valuemember Dianna K Microsoft Dot NET 0 2nd Dec 2003 10:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:54 PM.