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 8642085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:41:17+00:00 2026-06-12T11:41:17+00:00

I have a dictionary which I want to allow the keys to be selected

  • 0

I have a dictionary which I want to allow the keys to be selected in a combobox but also display the value without having to create another column.

For instance, if my dictionary consists of 3 items for now

Dictionary<string, double> test = new Dictionary<string, double>();
    //KEY , VALUE
    //"Item1" , 4.0
    //"Item2" , 4.5
    //"Item3" , 5.0

I want the combobox pulldown list to display the available selections showing BOTH key and value

[Item1, 4.0]
[Item2, 4.5]
[Item3, 5.0]

and say if [Item2, 4.5] is selected then only the key is displayed in the combobox as the current selection, in this case the following would display after selection…

Item2

I’ve tried the following but this shows [key,value] in both the combobox selection list and after selection

comboboxColumn2.SelectedValuePath= "Key";
comboboxColumn2.ItemsSource = test;

I’ve also tried using combinations with comboboxColumn2.DisplayMemberPath= "Value"; but cannot get it formatted as I would like.

Can anyone say if it’s possible and what the correct syntax is?

EDIT:

The combobox are actually ComboboxColumns so there are only 2 events available which don’t appear very useful

<DataGrid.Columns>
    <DataGridComboBoxColumn Header="Department Id" x:Name="comboboxColumn1"
            SelectedValueBinding="{Binding Department Id}" />
    <DataGridComboBoxColumn Header="Department Id" x:Name="comboboxColumn2"
        SelectedValueBinding="{Binding Department Name}"/>
</DataGrid.Columns>
  • 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-06-12T11:41:19+00:00Added an answer on June 12, 2026 at 11:41 am

    If you want to do this on code behind here it is :

    <ComboBox Height="23" HorizontalAlignment="Left" Margin="168,100,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" DropDownOpened="comboBox1_DropDownOpened" DropDownClosed="comboBox1_DropDownClosed" />
    
    public MainPage()
        {
            InitializeComponent();
            var source = new Dictionary<string, double>();
            source.Add("Item1", 0.4);
            source.Add("Item2", 0.3);
            source.Add("Item3", 0.1);
    
            var formateDSource = new Dictionary<string, string>();
    
            foreach (var item in source)
            {
                formateDSource.Add(string.Format("[{0}, {1}]", item.Key, item.Value), item.Key);
            }
    
            comboBox1.ItemsSource = formateDSource;
            comboBox1.DisplayMemberPath = "Value";
        }
    
        private void comboBox1_DropDownOpened(object sender, EventArgs e)
        {
            comboBox1.DisplayMemberPath = "Key";
        }
    
        private void comboBox1_DropDownClosed(object sender, EventArgs e)
        {
            comboBox1.DisplayMemberPath = "Value";
        }
    

    I just created an formatedSource and then changed the displayMemberPath according to your description.

    Hope it helps

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

Sidebar

Related Questions

I have 2 dictionary which contain the same keys but the value pairs are
I have a Dictionary<> which I want to sort based on value so I've
I have the following code: // Dictionary which I want to optimize Dictionary<string, MyClass>
I have a Dictionary<int, string> which I want to take the Key collection into
I have a uipickerview, which has a dictionary as a datasource. I want to
I have a dictionary to which I want to append to each drug, a
I have 2 objects, both of which I want to convert to dictionarys. I
I have a Dictionary which I am comparing to another Dictionary (variables typed as
I have a dictionary which is keyed by a List: private Dictionary<List<custom_obj>, string> Lookup;
I have a static dictionary which holds authentications for a web service. I'm running

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.