title: C# Bind TextBox To Specific Row Of DataTable
body: <p>I am building a simple C# application that allows the user to edit the rows of a table in a database. The interface is very simple, it is basically a list of rows and a few buttons. Selecting a row and pressing the "Add" button pops up a new form with text boxes for each column. I want those columns to be populated with the values for the selected row.</p>
  
  <p>After reading a few articles, I found that probably the simples way to do this is to bind the Text property of the TextBox to a DataSource. So I store the values from the database in a DataTable object, with the plan of retrieving the selected DataRow and binding its to the TextBox. This is the line I use:</p>
  
  <pre><code>productNameTextBox.DataBindings.Add(new Binding("Text", productRow, "Name"));
  </code></pre>
  
  <p>The result is the following exception:</p>
  
  <blockquote>
    <p>A first chance exception of type
    'System.ArgumentException' occurred in
    System.Windows.Forms.dll Cannot bind
    to the property or column Name on the
    DataSource. Parameter name: dataMember</p>
  </blockquote>
  
  <p>And yes, the "Name" column does exist.</p>
  
  <p>After reading  according to the documentation of bindings (http://msdn.microsoft.com/en-us/library/4wkkxwcz(v=VS.80).aspx) and many examples, it seems to me that one has to bind to the DataTable that the row is contained in. The following code worked for me:</p>
  
  <pre><code>productNameTextBox.DataBindings.Add(new Binding("Text", productRow.Table, "Name"));
  </code></pre>
  
  <p>Except it always sets the value of the TextBox to the first row. How do I specify which row to use?</p>