Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best practice for populating ComboBox ItemsSource?
Message
From
14/07/2008 13:19:53
 
 
To
All
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Title:
Best practice for populating ComboBox ItemsSource?
Miscellaneous
Thread ID:
01331114
Message ID:
01331114
Views:
56
As I stated in an earlier post, I will have a very common scenarion where I will have a ComboBox for picking a Customer from the list and binding that back to the database in a ForeignKey field. I will have this on over a dozen data input forms. I will also have lots more combos for picking other things (Vendords, Employees, etc)

So, I want to think about the best practice for populating ComboBoxes so that I do not have a lot of redundent code in the code-behind on all my forms.

Presently, I only have one form designed so far, and the ItemsSource property is established in the Constructor of the Window. But going forward, I want to have a class library or some strategy so that I have all this wired up already, that I just "drop" (or code) onto a form in a less hard-coding kind of way.

The ItemsSource will come from a very simple Linq call:
            IEnumerable<Customer> custs = from a in ctx.Customers
                                          select a;
            dropdownJobStatus.ItemsSource = custs; //Set the UI
Then here is the XAML:
        <ComboBox x:Name="dropdownJobStatus" Width="113" IsSynchronizedWithCurrentItem="True" AllowDrop="True" 
                  DisplayMemberPath="company" SelectedValuePath="custno" SelectedValue="{Binding Path=cust_num}"/>
Next
Reply
Map
View

Click here to load this message in the networking platform