Getting content from one column in a datagrid in a textbox

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
 
M

Mike McIntyre

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top