Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:29:53+00:00 2026-05-23T04:29:53+00:00

In my WPF app I have a data import function which imports data from

  • 0

In my WPF app I have a data import function which imports data from an Excel file into a database.

In order to allow user to map the columns from their Excel file to the columns in my database table I am displaying the list of Excel columns in a ComboBox next to database table column names allowing the user to select the matching Excel column from the ComboBox.

This is displayed in a ListBox with each item containing a ComboBox and a TextBlock.

The ListBox is Data Bound to a Dictionary<ColumnsClass, List<string>> where ColumnsClass is a simple object containing database column names and other details and the List<string> is just a list of column names found in the Excel file. In order to display the List<string> in the ComboBox I have a DataTemplate defined as such:

<DataTemplate x:Key="ColumnList">
    <Grid>
        <Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*"></ColumnDefinition>
    <ColumnDefinition Width="1*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
       <ComboBox Grid.Column="0" ItemsSource="{Binding Value, Mode=OneWay}">
   </ComboBox>
   <TextBlock Grid.Column="1" Text="{Binding Key, Mode=OneWay}"/>
    </Grid>
</DataTemplate>

Once the user maps the Excel columns to database column names and starts the import I need to be able to get the database column name and the matching ‘ComboBox’ ‘SelectedIndex’ value of each item in the ListBox but the each item in the ItemsSource is actually a KeyValuePair<ColumnsClass, List<string>> so I don’t see how to get the ‘ComboBox’ ‘SelectedIndex’ value while iterating through the ListBox.Items collection…

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:29:54+00:00Added an answer on May 23, 2026 at 4:29 am

    If you use the Dictionary just as a IEnumerable<KeyValuePair<ColumnsClass, List<string>>>, you could create a custom class to hold the two values and add a value specifying user’s choice:

    class ViewModel
    {
        public ColumnClass ColumnClass { get; set; }
        public List<string> ColumnNames { get; set; }
        public string SelectedColumn { get; set; }
    }
    

    Then use List<ViewModel> (or any other collection) instead of your Dictionary and bind to SelectedColumn in your XAML:

    <DataTemplate x:Key="ColumnList">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ComboBox Grid.Column="0" ItemsSource="{Binding ColumnNames, Mode=OneWay}"
                SelectedItem="{Binding SelectedColumn}" />
            <TextBlock Grid.Column="1" Text="{Binding ColumnClass, Mode=OneWay}"/>
        </Grid>
    </DataTemplate>
    

    If, for some reason, you didn’t want to create a separate class and you’re on .Net 4, you could use Tuple<ColumnClass, List<string>, string> instead of ViewModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have data files which are encrypted in our wpf app. We would like
I have a WPF app which, when it starts, looks at the file system
I have a WPF app which snaps to screen edges (I just set the
I have a WPF App which is grinding to a halt after running out
In WPF app I have a WCF service which dynamically fills a generic List
In my WPF app I have implemented LINQ to SQL query which populates an
I have a WPF app that is currently driven completely from XAML. All fields,
I've got a situation which I want to fetch data from a database, and
Background: We have a ClickOnce-deployed WPF app, that talks to WCF Services, which in
I'm creating a WPF app and have a system tray icon with a context

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.