Question DataSource erases DisplayMember...why?

EliW

New member
Joined
Jun 1, 2010
Messages
1
Programming Experience
10+
Throughout our VB.NET application, we populate combo boxes and grids using SQL queries. The queries are usually run by a WCF service which the client software calls via a presenter.

We set the .DisplayMember and .ValueMember before setting the .DataSource, because we read somewhere that it's more efficient. (I don't have the link with me, but it was something to do with getting the control to draw or paint faster.)

Usually, code like the sample I've included below works fine:

VB.NET:
            Dim objSearchParms As New CustomerSearchBE
            objSearchParms.CustomerName = "NameImSearchingFor"
            objSearchParms.CustomerNbr = "NumberImSearchingFor"

            With cboName
                .DisplayMember = "CustomerName"
                .ValueMember = "CustomerNbr"
                ' The _presenter method below returns
                ' a List(Of CustomerSearchBE) containing
                ' the search results.
                .DataSource = _presenter.GetMatchingCustomers(objSearchParms)
            End With

In this particular instance, though, I've discovered that setting the .DataSource property mysteriously causes the .DisplayMember property to be erased. I've stepped through the code and discovered that after the .DataSource command, .DisplayMember is set to "". Because of this, combo box cboName displays nothing but "Blah.Blah.Blah.CustomerSearchBE" over and over, which is the .ToString result.

Oddly enough, the .ValueMember is unaffected...just the .DisplayMember is erased.

I guess I'll just have to repeat (or move) the .DisplayMember command after the .DataSource for now, to get this code working properly. But why is this happening all of a sudden?
 
Back
Top