Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WPF ComboBox Problem
Message
From
02/07/2010 13:37:01
 
 
To
02/07/2010 12:05:59
Guy Pardoe
Pardoe Development Corporation
Peterborough, New Hampshire, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01471290
Message ID:
01471296
Views:
63
>Hi,
>
>I'm using MM.NET v4.0 doing a WPF app and I've spent a lot of time trying to sort out a combo box problem. I've been double-checking against the MM.NET doc and also trying different possibilities as I did google searches, and I've looked at this so long that I've gone brain dead. I could use another pair of eyes to tell me if something obvious jumps out that I may be doing wrong regarding WPF ComboBoxes in MM.NET.
>
>I have a WPF combo box with an item source of an EntityList being returned from a business object (in turn, referencing a stored proc from a SQL database).
>
>
>this.cboActions.ItemsSource = this.ActionsController.GetActionsListBySortOrder();
>
>
>This loads correctly and I can see the proper values in the debugger.
>
>
>The XAML for the combobox (excluding sizing, alignment, etc) is:
>
>
><ComboBox x:Name="cboActions" DisplayMemberPath="ActionName" SelectedValuePath="ActionCode" 
>SelectedValue="{Binding Path=Action, Mode=TwoWay}" />
>
>
>I understand these properties mean:
>
>DisplayMemberPath = The column name used from the ItemsSource to display what I want in the combo box. In my case, a user friendly Action Name
>
>SelectedValuePath = The column name used from the ItemsSource to be the 'key' value that will be written back to the primary business object on the form when the user makes a selection in the combo box. Basically a foreign key value.
>
>SelectedValue = The property value from the primary business object (i.e., binding path) that is linked to the SelectedValuePath.
>
>My form has textboxes, checkboxes, and this one combobox where I am having the problem. Everything works correctly for all fields on the form except this one thing... When the WPF form first loads, the initial view of combo box appears empty. It is loaded with the proper list values (entity values) and I can make selections in the combo box and my choice is properly saved to the database. But each time I open the form, it's initial display value is blank.
>
>I have tried a million different settings in both the XAML and by writing code in the code-behind page. The only thing that has come close to working is that in the code-behind page, I can hard-code a specific integer to be the SelectedIndex, and then I get a proper value displayed when I test it this way. But, of course, I cannot be hard-coding values like this for the production app. Interestingly, when I try to programmatically set the SelectedIndex by chasing after the Items.IndexOf() for my particular value from the business object, that fails as well. But kludges like this shouldn't be necessary in the first place. I figure there must be some simple thing that I am missing. But from all the samples in the doc and on the Internet, I can't see what I'm doing wrong.
>
>Any ideas?

I'm not very familiar with MM but just maybe:
<ComboBox x:Name="cboActions" DisplayMemberPath="ActionName" SelectedValuePath="ActionCode"
           IsSynchronizedWithCurrentItem="True"></ComboBox>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform