Print Page | Close Window

ComboBox Binding in a DataForm

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2074
Printed Date: 10-Jun-2026 at 5:03pm


Topic: ComboBox Binding in a DataForm
Posted By: wwlgray
Subject: ComboBox Binding in a DataForm
Date Posted: 18-Aug-2010 at 1:26pm

I have 2 tables that I am binding to a combobox inside a DataForm. The first table is the Collection built from the Devforce entity and the second is a lookup table brought into a static resource.

With the code below the combobox selects and updates the data, however when the dataform is bound we cannot get the current value to display. I need the current value to show when the form loads.

 

<ComboBox Name="cmbStatus"

          ItemsSource="{Binding StatusLookups,Source={StaticResource statusLookups}}"

          DisplayMemberPath="Description"

          SelectedItem="{Binding Path=Status_FK,Mode=TwoWay}"

          SelectedValuePath="StatusCode_PK"/>

 




Replies:
Posted By: ting
Date Posted: 19-Aug-2010 at 5:25pm
Did you take a look at this link which shows how to work with ComboBoxes?:
http://www.ideablade.com/Videos/SamplesGrabBag/index.html - http://www.ideablade.com/Videos/SamplesGrabBag/index.html
 


Posted By: wwlgray
Date Posted: 25-Aug-2010 at 7:04am
Yes I have watched the video. Is there a sample with that code? I have tried it and it is not working for me.


Posted By: BillG
Date Posted: 25-Aug-2010 at 9:37am
Here is a sample of one that I have done. It works fine.
 
                                <ComboBox Name="VendorsComboBox" ItemsSource="{Binding Vendors}"  DisplayMemberPath="VendorName" Style="{x:Static Office2007:Office2007BlueResources.ComboBoxStyle}" SelectedValuePath="VendorId" Grid.Column="4" Grid.Row="0" SelectedValue="{Binding Path=CurrentItem.VendorId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" IsSynchronizedWithCurrentItem="True" Width="170" HorizontalAlignment="Left" Height="20" TabIndex="4" />
 
In my view code behind in my loaded event I have the following statement.
 
this.DataContext = aModel                                      aModel is an object of the InventoryViewModel
 
 
in my VendorViewModel I have a private property called currentItem which has a public getter/setter called CurrentItem. currentItem contains the current Inventory item being worked on.
 
Bill

 


Posted By: wwlgray
Date Posted: 26-Aug-2010 at 5:50am
Ok, Here is what I have
 
The dataform is in a child window popup. At form load I set the CurrentItem to the item I want to work on. In the Xaml I have a static resource of an ObservableColletion<object> as my itemsource. I have set in Xaml the SelectedValue and SelectedItem to my CurrentItem.Status_FK and the SelectedValuePath to the StatusCode_PK of the object as shown below.
 
<ComboBox x:Name="cmbStatus"
ItemsSource="{Binding StatusLookups, Source={StaticResource statusLookups},Mode=TwoWay}"
SelectedItem="{Binding Path=CurrentItem.Status_FK}"
SelectedValue="{Binding Path=Status_FK,Mode=TwoWay}"
SelectedValuePath="StatusCode_PK"
DisplayMemberPath="Description" />
 
On formload I set the dataform to edit. The currentitem.status_fk is not shown in the combobox.

this.projForm.CurrentItem = CurrentProject; // where the CurrentProject is the mainform selected item.

this.projForm.BeginEdit();




Print Page | Close Window