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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:42:51+00:00 2026-06-12T02:42:51+00:00

I want to bind a textBox’s data to a Dictionary<string,string> entry. I am trying

  • 0

I want to bind a textBox’s data to a Dictionary<string,string> entry. I am trying to achieve this through data binding, so the content get updated after the user edited the textBox.

This is a demo code of what I have done:

A classA that has a Name and List dictionary:

class ClassA
{
    public string Name { get; set; }
    public Dictionary<string, string> List { get; set; }

    public ClassA()
    {
        this.Name = "Hello";

        this.List = new Dictionary<string, string>
        {
            {"Item 1", "Content 1"},
            {"Item 2", "Content 2"}
        };
    }
}

In the Form, I bind textBox1 to Name and textBox2 to List["Item 1"]:

ClassA temp = new ClassA();

public Form1()
{
    InitializeComponent();

    textBox1.DataBindings.Add("Text", temp, "Name");
    textBox2.DataBindings.Add("Text", temp.List["Item 1"], "");

    label1.DataBindings.Add("Text", temp, "Name");
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
    label1.Text = temp.List["Item 1"];
}

If I change textBox1 text, label1 content (Name) will successfully updated.

But if I change textBox2 text, label1 content will show the original List["Item 1"] value.

How can I bind textBox2 to List["Item 1"] correctly?

  • 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-12T02:42:52+00:00Added an answer on June 12, 2026 at 2:42 am

    Use explicit binding and consume its events to achieve your goal

            Binding binding = new Binding("Text", temp, "List");
            binding.Parse += new ConvertEventHandler(binding_Parse);
            binding.Format += new ConvertEventHandler(binding_Format);
            textBox2.DataBindings.Add(binding); 
    

    Parse event will occur when the value of a data-bound control changes.

        void binding_Parse(object sender, ConvertEventArgs e)
        {
            temp.List["Item 1"] = e.Value.ToString();
            label1.Text = temp.List["Item 1"]; 
        }
    

    Format event will occur when the property of a control is bound to a data value.

        void binding_Format(object sender, ConvertEventArgs e)
        {
            if (e.Value is Dictionary<string, string>) 
            { 
                Dictionary<string, string> source = (Dictionary<string, string>)e.Value;
                e.Value = source["Item 1"];
    
            } 
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I have been trying to iron out this data binding for a
I have a textbox on which i want to bind multiple autocomplete JSON data.
I want to Bind a String element in a List to a Textbox. When
i want to bind textbox But it isn't display the string. Second thing is
I want to bind a textbox to a data source so that I can
I want to bind a string value to a text box but only if
I want to bind Groupboxes to my stackpanel. c#: internal ObservableCollection<GroupBox> BindingTest { get
I want to bind to a value in a dictionary property of an object.
I want to bind one property to multiple sources. My reason for this are
Normally we bind a textbox's Text property to a data-context's properties. The data-context can

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.