Wpf combobox not synchronizing with underlying records

Topics: Prism v2 - WPF 3.5
Jan 26, 2010 at 2:46 PM

I have a wpf program with a shell window that has 2 regions. (Navigation and Details).

I have a class that holds a list of jobs that a driver has to complete.

The class has fields for

Customer , Address, JobDate, Balance, WasteTypeID etc.

In the Navigation view i display the jobs in a list hust showing Customer and Address.

When the user selects a job from the navigation view it publishes.  In the Details view i subscribe to this event and display the rest of the details for the selected job.

The above all works fine.  The problem i have is that i have a combobox in the details view that displays a list of waste types that i gets from the database.  I want this combobox to dispaly the waste type description that relates to the WasteTypeID on the underlying data.

The list of waste types are showing in the combobox, so it is getting populated.  What's happening is that the first item in the list is always the selected item no mater what record i select in the navigation view.

do i need to requery/update in some way to get it to bind properly to WasteTypeID

Here's my xaml for the combobox:

<

<font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

 

</font></font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

 

</font></font><font face="Consolas" size="2" color="#0000ff">

 

</font>

ComboBox x:Name="CboWasteTypes" IsEditable="False" <font face="Consolas" size="2"><font face="Consolas" size="2">

 

</font></font><font face="Consolas" size="2">

 

</font>

IsSynchronizedWithCurrentItem="True" <font face="Consolas" size="2"><font face="Consolas" size="2">

 

</font></font><font face="Consolas" size="2">

 

</font>

ItemsSource="{Binding}" <font face="Consolas" size="2"><font face="Consolas" size="2">

 

</font></font><font face="Consolas" size="2">

 

</font>

DisplayMemberPath="WasteType" <font face="Consolas" size="2"><font face="Consolas" size="2">

 

</font></font><font face="Consolas" size="2">

 

</font>

SelectedValuePath="WasteTypeID" <font face="Consolas" size="2"><font face="Consolas" size="2">

 

</font></font><font face="Consolas" size="2">

 

</font>

SelectedValue="{Binding Path=WasteTypeID}" 

Width="200"

The comboboxes datacontext is getting set in the view model when the user selects a job in the navigation view

I've been looking for a solution to this for a couple of days now.  Coming from a msaccess background this seems to be a lot of headache to do something fundamental.  Maybe i'm looking at this to long. 

Any help would be appreciated.

Thanks

Paul

Jan 26, 2010 at 6:04 PM

Hi Paul,

Without knowing the specific of your application, I have tried to reproduce your scenario with no success. I have uploaded a small repro sample here so you can compare the differences with your version. In the sample:

  • Changing the item in the List will automatically change the item in the Combo.
  • Changing the item in the Combo will automatically change the item in the List.
  • Clicking the button will automatically move to the next item.

If the above does not help you troubleshoot your issue, please provide a repro sample so we can help you with this. You could also try asking this question in the WPF forum.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Jan 27, 2010 at 9:57 AM

Thanks for the reply and example Damian.  My scenario is that the navigation and details are in 2 seperate modules.  There is a wastetypeid field in the jobs table.  I populate a combobox with a list of waste types from a waste types table.  I want the combobox to show the waste type description in the combobox for the wastetypeid thats in the jobs table.

How can i upload a repro sample?

I'm new to all this :)

Thanks again

Paul

 

 

Jan 27, 2010 at 11:23 AM

Hi Damian

I've added a sample copy of what i'm working on here http://cid-3cd5bdc4e5b0165a.skydrive.live.com/self.aspx/apps/ComboBoxSample.zip

Thanks

Paul

Jan 27, 2010 at 2:04 PM

Hi Paul,

I have downloaded the repro sample you have provided, but I have not been able to load the following projects:

  • Infrastructure
  • Work
  • WorkItems

I have not been able to find those projects in the .zip file you uploaded and they are referencing the following path “'C:\Users\User\Visual Studio 2008\Projects\…”.

It could also be useful (if possible) if you could create some in-code mock data for the jobs information instead of having to pull it from the database for this simple example.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Jan 28, 2010 at 1:49 PM

Hi Damian

Sorry about the previous link. Still learning :)

Anyway heres a new link with in-code mock data http://cid-3cd5bdc4e5b0165a.skydrive.live.com/self.aspx/apps/ComboBoxSample.zip

Thanks for your time

Paul