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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:51:35+00:00 2026-06-01T22:51:35+00:00

Update: Just need to return a key from a dictionary, the dictionary is created

  • 0

Update: Just need to return a key from a dictionary, the dictionary is created by a web service, and passed back to my program which is a WPF, the dictionary is then populated into a dropdown that contains the following values

IT_ED
IT_FS
IT_BUS

The keys are assigned are as follows

Key Value
[1] IT_ED
[2] IT_FS
[3] IT_BUS

I need the key from the value, based on which item is selected in the drop down menu

Dictionary i use to house the keys

private Dictionary<int, string> _DivisionDict = new Dictionary<int, string>();

private Dictionary<int, string> DivisionDict
{
    get { return _DivisionDict; }
    set { _DivisionDict = value; }
}

Heres how I populate my drop down menu and the dictionary with the keys

foreach (var D in Divisions)
{
   txtY.Items.Add(D.Value);
   DivisionDict.Add(D.Key, D.Value);
}
  • 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-01T22:51:36+00:00Added an answer on June 1, 2026 at 10:51 pm

    Ok, that’s better now (the question),
    So, if I get it right you’d like to get back an ‘index’ from the selected item in the WPF dropdown (i.e. ComboBox).

    First, easiest is to do a proper data ‘binding’ through your view-model,

    ItemsSource="{Binding YourDictionaryProperty}" 
    SelectedItem="{Binding Path=YourDictionarySelectedItem, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"  
    DisplayMemberPath="Value"
    
    • Expose your dictionary through the View Model class. Like a property
      you did create,
    • put view model as your data context for the combobox (or parent etc.),
    • both properties used for binding (YourDictionarySelectedItem and YourDictionaryProperty) are properties in your view model. One exposes Dictionary ‘as is’, and another is KeyValuePair …SelectedItem. Just FYI,
    • do something like the above…

    …then in your YourDicitonarySelecteItem in your view model – you’ll have the KeyValuePair from the dictionary. And from that you know both index and the value.

    Or a brute force would be to find the selected value (if you have that as ‘output’ based on how you currently set things up) in the dictionary via e.g. LINQ like this…

    Divisions.Where(d=>d.Value == "selected value").FirstOrDefault();  
    

    …that’d give you the ‘pair’ and from that take the Key.

    hope we nailed it this time:), cheers

    EDIT: proper dictionary binding was not in the original scope so it’s a fast fix solution. If you need to update the dictionary ‘from behind’ you’d need to use some observable collection – or force OnPropertyChanged on the full dictionary whenever its items change. See this link for more specific info on that,
    Two Way Data Binding With a Dictionary in WPF

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

Sidebar

Related Questions

Update: I just tested my JSON format returned from the server using JSONlint and
I was just reading an update from a friend's project, mentioning the use of
I need to get just the first item (actually, just the first key) off
I need to find the next available ID (or key) from a fixed list
UPDATE: So pretty much everyone here has told me that I just need to
I have developed a windows forms c# application, i just want update items in
I just did an update of my SDK and now eclipse is giving me
I just used Android SDK Manager to update Android SDK Tools to revision 17,
I was just asked to update my settings in xcode as I was getting
I just installed Eclipse Galileo for Java developers and noticed that the update site

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.