New Posts New Posts RSS Feed: ComboBox Binding in a DataForm
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

ComboBox Binding in a DataForm

 Post Reply Post Reply
Author
wwlgray View Drop Down
Newbie
Newbie
Avatar

Joined: 18-Aug-2010
Location: Florida
Posts: 8
Post Options Post Options   Quote wwlgray Quote  Post ReplyReply Direct Link To This Post Topic: ComboBox Binding in a DataForm
    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"/>

 

Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 424
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 19-Aug-2010 at 5:25pm
Did you take a look at this link which shows how to work with ComboBoxes?:
 
Back to Top
wwlgray View Drop Down
Newbie
Newbie
Avatar

Joined: 18-Aug-2010
Location: Florida
Posts: 8
Post Options Post Options   Quote wwlgray Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 177
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post 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

 
Back to Top
wwlgray View Drop Down
Newbie
Newbie
Avatar

Joined: 18-Aug-2010
Location: Florida
Posts: 8
Post Options Post Options   Quote wwlgray Quote  Post ReplyReply Direct Link To This Post 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();

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down