title: How can I bind a Winform textbox to a class property?
body: <p>I have read a number of questions on Stack Overflow and elsewhere that describe tying a textbox to a class but I cannot seem to even get the basics working without receiving an error from VS when compiling.</p>
  
  <p>(1) What I want to accomplish is to display the text of a property from a class.</p>
  
  <p>(2) When the user modifies that text, I want the property to automatically update.</p>
  
  <p>Unfortunately I cannot even get past (1) yet.</p>
  
  <p>The class:</p>
  
  <pre><code>class BookProperties : INotifyPropertyChanged
  {
  
      private string _bookTitle;
      public string bookTitle { get { return _bookTitle; } set { SetField(ref _bookTitle, value, "bookTitle"); } }
  
      #region handle property changes
  
      public event PropertyChangedEventHandler PropertyChanged;
      protected virtual void OnPropertyChanged(string propertyName)
      {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
      }
      protected bool SetField&lt;T&gt;(ref T field, T value, string propertyName)
      {
          if (EqualityComparer&lt;T&gt;.Default.Equals(field, value)) return false;
          field = value;
          OnPropertyChanged(propertyName);
          return true;
      }
  
      #endregion
  }
  </code></pre>
  
  <p>The class initializer:</p>
  
  <pre><code>BindingList&lt;BookProperties&gt; bookProperty = new BindingList&lt;BookProperties&gt;();
  </code></pre>
  
  <p>The connection to the textbox:</p>
  
  <pre><code>    textBox1.DataBindings.Clear();
      textBox1.DataBindings.Add("Text", bookProperty, "bookProperty.bookTitle");
  </code></pre>
  
  <p>I have also tried this:</p>
  
  <pre><code>    textBox1.DataBindings.Clear();
      textBox1.DataBindings.Add("Text", bookProperty, "bookProperty[0].bookTitle");
  </code></pre>
  
  <p>Visual Studio throws the following error:</p>
  
  <blockquote>
    <p>Child list for field bookProperty cannot be created.</p>
  </blockquote>
  
  <p><strong>START EDIT:</strong> Trying this code, I remove the additional element from the third parameter as a few have suggested.</p>
  
  <pre><code>bookProperty.Add(new BookProperties(){bookTitle="C#"});
  textBox1.DataBindings.Add("Text", bookProperty[0], "bookTitle");
  </code></pre>
  
  <p>Now, I receive this error. I had received it before and searched for a resolution but think it might be too generic for me to figure out what exactly I am doing wrong.</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.ArgumentException' occurred in
    System.Windows.Forms.dll</p>
    
    <p>Additional information: This causes two bindings in the collection to
    bind to the same property.</p>
  </blockquote>
  
  <p><strong>END EDIT</strong></p>
  
  <p>I am starting to think there is something fundamentally wrong with my approach since I have seen similar code that people say works so I am hopeful someone can tell me what I am doing wrong. Please note this is a Windows Form issue, not XAML. Thanks.</p>
  
  <p><strong>FIXED</strong>
  Sorry about the last edit. It turns out I had previously attempted to manually link the textbox to a data source using the VS designer. After I removed that data source, everything worked. Thank you for the help!</p>