Getting content from one column in a datagrid in a textbox

  • Thread starter Thread starter reidarT
  • Start date Start date
R

reidarT

I have a datagrid with columns. One of the columns are a textbox.
I want the text in this column shown in a textbox outside the datagrid.
How can I do that when clicking the actual row in the datagrid?
reidarT
 
You can bind the Text property of your 'off the grid' TextBox to your
DataGridView's BindingSource text column and the TextBox will display the
text for the row selected in the DataGridView.

..1 At design time you can select the TextBox that is outside the
DataGridView, view its properties, select DataBindings -> Advanced to open
the 'Formatting and Advanced Binding' dialog where you can associate the
column of the BindingSource with the TextBox.

OR

2. For runtime binding you will need to add code similar to this to bind the
TextBox Text property to the BindingSource:
Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.CustomerBindingSource, "Name", True))

The example above shows the Text property of a TextBox named TextBox1 being
bound to the "Name" column of a BindingSource named CustomerBindingSource.
 
Back
Top