Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

populating combobox

Posted on 2010-08-31
7
Medium Priority
?
726 Views
Last Modified: 2013-11-12
I want populate a combobox in WPF with the data that I have in LINQ to SQL result set.  I'm not sure what to do in the xaml side to hook the results that I got from LINQ to SQL.  I have 2 codes below

(1) my xaml for the dropdown combobox being used in WPF.
(2) my window_loaded routine getting the results into DataList

thanks
nick
<Window x:Class="WPF_Statement_View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="651" Width="703" xmlns:igDP="http://infragistics.com/DataPresenter" Loaded="Window_Loaded">
    <Grid Height="516">
        <Grid.RowDefinitions>
            <RowDefinition Height="355*" />
            <RowDefinition Height="2*" />
        </Grid.RowDefinitions>
        <igDP:XamDataGrid HorizontalAlignment="Left" Margin="0,49,0,0" Name="xamDataGrid1" Width="681" Height="378" VerticalAlignment="Top" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="64,12,0,0" Name="comboBox1" VerticalAlignment="Top" Width="171" ItemsSource="{Binding }" />
        <Label Content="Date" Height="28" HorizontalAlignment="Left" Margin="22,12,0,0" Name="label1" VerticalAlignment="Top" Width="65" />
    </Grid>
</Window>

Open in new window

namespace WPF_Statement_View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            Statements_ARDataContext db = new Statements_ARDataContext();

            var DateList = from t in db.StatementDates 
                                 select t;
    
        }
    }
}

Open in new window

0
Comment
Question by:countyprob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:vbigham
ID: 33572598
comboBox1.ItemSource = DateList

That should probably do the trick in code.  If you want to do it in XAML you be looking into a CollectionViewSource or something... I usually just set the itemssource in code.  But the ComboBox will want a DisplayMemberPath set in XAML (ex. <ComboBox Height="23" DisplayMemberPath="Date" Name="combobox1" />)
0
 
LVL 1

Author Comment

by:countyprob
ID: 33588564
Thanks for replying vbigham.  I tried your solution.  The dropdown populates but it doesn't show the date.  The dropdown shows "WPF_statements_process.statementdate."  How can I get to the date.  Thanks. ..nick..
0
 
LVL 7

Expert Comment

by:vbigham
ID: 33591728
Ok, so the DisplayMemberPath will want to be the name of the field where you are actually storing the date.  So, I am not sure what WPF_statements_process.statementdate looks like, but I am thinking that you should do something like this DisplayMemberPath="statementdate.DESIREDFIELD"  replace DESIREDFIELD with the actual name of the date that you want to show up.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 7

Expert Comment

by:vbigham
ID: 33591737
Actually, you might not even need the statementdate part, just the name of the field where the date is stored.
0
 
LVL 1

Author Comment

by:countyprob
ID: 33591852
Actual the route I went was using:

comboBox1.ItemSource = DateList

Do I still need to get involved with DisplayMemberPath in xml?  Currently it seems not to display the date that is captured in the DateList.  I'm not sure how to drilldown in the DateList to get to the dates.

thanks
nick
0
 
LVL 7

Accepted Solution

by:
vbigham earned 2000 total points
ID: 33591883
Yes, It wants a display member path to tell it where to find your desired date.  Otherwise it will just use the immediate object's ToString() which is probably why you are seeing WPF_statements_process.statementdate instead of a more meaningful value.

if you set a breakpoint right after this statement, you should be able to examine the datelist to find the field you want to show.

var DateList = from t in db.StatementDates  
                                 select t;  
0
 
LVL 1

Author Closing Comment

by:countyprob
ID: 33599365
great solution.  Thanks for the help
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question