Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WPF ComboBox Problem
Message
De
06/07/2010 10:35:06
Guy Pardoe
Pardoe Development Corporation
Peterborough, New Hampshire, États-Unis
 
 
À
03/07/2010 05:16:01
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01471290
Message ID:
01471520
Vues:
49
This message has been marked as the solution to the initial question of the thread.
The problem is solved. I'm posting this as a reminder to myself and anyone else who may stumble across this type of problem.

I started looking deeper with the debugger and noticed once the data context was set in the code-behind page, my bindings were set properly and the SelectedValue ~was~ showing the correct value from the business object for the particular record that was loaded. However, the next line of code set the ItemSource for the combo box and the SelectedValue was not found in the SelectedValuePath. Therefore the combo box displayed with nothing selected.

My problem was a difference in field lengths in the SQL Database between SelectedValue and SelectedValuePath. This project involves the merging of three disparate legacy databases and I had not noticed this particular data field was not consistent from one table to another. Thus,
"ABC"
was not equal to
"ABC   "
(with a few blank characters at the end). This is what caused the combo to not synchronize against it's SelectedValuePath. Once the fields lengths were adjusted to be the same, the combo box works perfectly. The bottom line is... size matters.

Thanks for all the help and suggestions on this thread.

Guy










>Hi,
>Don't see how the ComboBox can show anything without the ItemsSource being set?
>
>Anyway, looking again at your XAML (and assuming the Action property of the DataContext is an instance of that class), I think it should be either:
<ComboBox x:Name="cboActions" DisplayMemberPath="ActionName" SelectedValuePath="ActionCode"
>        SelectedItem="{Binding Action}">
> </ComboBox>
or
<ComboBox x:Name="cboActions" DisplayMemberPath="ActionName" SelectedValuePath="ActionCode"
>        SelectedValue="{Binding Action.ActionCode}">
></ComboBox>
but I don't know which fits your requirements (probably the first)
>
>Or am I just wrong about what Action in the DataContext is?
>
>
>>I am looking at this closer in the debugger and I am seeing that the combo box has valid (synchronized) values after the data context is set, but then they get blown away (null) when the ItemsSource is set.
>>
>>
>>    this.InitializeComponent();
>>
>>    this.LayoutRoot.DataContext = this.CATController.GetCATargetByPK(PK);
>>    this.cboActions.ItemsSource = this.ActionsController.GetActionsListBySortOrder();
>>
>>
>>I'm going to try to reset the selectedvalue bindings in code after the ItemsSource has been loaded and see what that does.
>>
>>Guy
>>
>>
>>
>>>HI,
>>>Hmmm. Bit hard to know what's going on without knowing more about the ItemsSource. What dicatates which item in the list should be selected after loading ?
>>>
>>>>I notice also that after having removed the SelectedValue section from the XAML, any changes I make to the select values in the combobox are not saved back to the business object (and database).
>>>>
>>>>:(
>>>>
>>>>Guy
>>>>
>>>>
>>>>>Hi,
>>>>>As posted I'd expect that to put some initial value in the ComboBox. Did you remove the
>>>>>SelectedValue="{Binding Path=Action, Mode=TwoWay}"
>>>>>?
>>>>>
>>>>>>I've tried that. Same results. :(
>>>>>>
>>>>>>
>>>>>>>I'm not very familiar with MM but just maybe:
<ComboBox x:Name="cboActions" DisplayMemberPath="ActionName" SelectedValuePath="ActionCode"
>>>>>>>           IsSynchronizedWithCurrentItem="True"></ComboBox>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform