views:

512

answers:

1

I'm trying to alter how a combobox is displayed using the following code:

    private void UpdateMapRoadPointList(List<GeographicAddress> plstMapRoadPointList)
    {
        cboFind.DataSource = plstMapRoadPointList;
        cboFind.DisplayMember = "ShortCode";
        cboFind.ValueMember = "";
    }

GeographicAddress is a class which has a ShortCode property which returns a string:

    internal string ShortCode
    {
        get { return Distance + Carriageway; }
    }

However, when using the application, the disaplyed value is still coming from GeographicAddress.ToString(). On debugging, it seems that cboFind.DisplayMember = "ShortCode" is having no effect! DisplayMember is "" before and after executing that line!

What am I missing?

+3  A: 
public string ShortCode
    {
        get { return Distance + Carriageway; }
    }

private void UpdateMapRoadPointList(List<GeographicAddress> plstMapRoadPointList)
    {
        cboFind.DataSource = plstMapRoadPointList;
        cboFind.DisplayMember = "ShortCode";
    }

this should work

Set ShortCode property to Public or it will fail and use GeographicAddress.ToString()

Hath
Yeah - the property needed to be public. Silly me!
Paul Smith