Re: DisplayMember / ValueMember Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Peter Foot [MVP] (feedback_at_nospam-inthehand.com)
Date: 02/28/04


Date: Sat, 28 Feb 2004 09:17:33 -0000

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" <james_stutz@hotmail.com> wrote in message
news:d0f96e56.0402271927.dc3b44@posting.google.com...
> 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


Relevant Pages

  • Re: Composite primary key to other table as foreign key?
    ... all mushed together as a single field for display purposes. ... Where is the best place to concatenate the fields for the closed combo ... The query is the right place. ... combobox, and include formatting characters too, if you like. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Combo box / Subform Question
    ... After the combobox selection is made, ... the query sees the selected record and that one gets displayed on ... "Jeff Boyce" wrote: ... value to find the correct record to display. ...
    (microsoft.public.access.formscoding)
  • Re: Query to populate combobox with names of tables, only if they contain data
    ... my case, I wanted to not display the names of empty tables at all, so I ... SELECT "data-chiroptera" AS TableName, Countas RecordCount ... I have a form with a combobox, populated by names of tables in the ... The source for the combobox was this query: ...
    (microsoft.public.access.forms)
  • How to add a chosen value from a combo box into a text box
    ... if you want to *display* the value in an unbound textbox control, ... replace n with the column index number (remembering the index in a combobox ... tblCompany, with 3 columns: CompanyID, CompanyName, PIC. ...
    (comp.databases.ms-access)
  • Re: How do I populate my combobox - I know...its been asked.
    ... If the Properties window is not displayed in the Visual Basic Editor, ... the View menu to display it. ... Initialize event of the form to populate the combobox. ... I plan on using this script three times but w/ different information ...
    (microsoft.public.word.newusers)