0

Hey I have a question about getting an ContactTypeId from the ContactType. This is the object that has an id:

public class ContactType
{
    public int ContactTypeId { get; set; }

    public string ContactTypeValue { get; set; }

    public int ContactId { get; set; }

    public DateTime? Added { get; set; }
    public DateTime? Updated { get; set; }
    public DateTime? Deleted { get; set; }

}

I wrote a WPF application that has a listbox.

<ComboBox x:Name="ContactTypeComboBox" HorizontalAlignment="Left"     Margin="110,68,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding ContactTypes}" DisplayMemberPath="ContactTypeValue" SelectedValuePath="ContactTypeId"  />

If i get Selected value path doesn't give an ContactTypeId from that object. It only gives a string "ContactTypeId"

Please help me to get a ContactTypeId from ContactType

anduplats
  • 885
  • 2
  • 14
  • 24
  • I think http://stackoverflow.com/questions/4902039/difference-between-selecteditem-selectedvalue-and-selectedvaluepath and http://stackoverflow.com/questions/3797034/confused-with-wpf-combobox-displaymemberpath-selectedvalue-and-selectedvaluepath will benefit you. – J. Hasan Apr 30 '16 at 15:40

1 Answers1

0

SelectedValuePath tells the control how to drill down into the selected item and extract a value. The value for the selected item (in this case, its ContactTypeId) is exposed as SelectedValue. That's the property you want to read.

Mike Strobel
  • 25,075
  • 57
  • 69