Tying a textbox to a datagrid

N

Nevyn Twyll

On a Windows form, I get a dataset and bind it to a datagrid.
I also want to have a textbox on that form I want to show the full text of a
column in the currently selected row of the datagrid.

How do I bind a textbox to show the contents of a column in the currently
selected row of a datagrid?

Help?

- nevyn
 
N

Nevyn Twyll

I tried that and it didn't seem to work. It binds it to the first value in
the list, but doesn't change when the datagrid changes rows.

I have:

DataSet ds = sqlconnection.ExecuteDataSet(...)
this.dgrdSample.DataSource = ds.Tables[0];
ds.Tables[0].TableName = "MyTable";
txtMainText.DataBindings.Add(new Binding("Text", ds,
"MyTable.MyTextField"));

help?
 
M

MajorTom

DataSet ds = sqlconnection.ExecuteDataSet(...)
ds.Tables[0].TableName = "MyTable";

this.dgrdSample.DataMember = "MyTable";
this.dgrdSample.DataSource = ds;

txtMainText.DataBindings.Add(new Binding("Text", ds,
"MyTable.MyTextField"));

if not ask againg

MajorTom

Nevyn Twyll said:
I tried that and it didn't seem to work. It binds it to the first value in
the list, but doesn't change when the datagrid changes rows.

I have:

DataSet ds = sqlconnection.ExecuteDataSet(...)
this.dgrdSample.DataSource = ds.Tables[0];
ds.Tables[0].TableName = "MyTable";
txtMainText.DataBindings.Add(new Binding("Text", ds,
"MyTable.MyTextField"));

help?

William Ryan eMVP said:
Set the databindings of the text box to the same source
text
 
N

Nevyn Twyll

Yeah, that's what I had - it binds the textbox to the first entry in the
dataset.
But when I move the current record in the grid, how do I get the textbox to
change?
I couldn't seem to find a rowchange event on the grid?
ANd, to get it to really work, shouldn't I bind the textbox somehow to the
datasource of the grid?

- Nevyn

MajorTom said:
DataSet ds = sqlconnection.ExecuteDataSet(...)
ds.Tables[0].TableName = "MyTable";

this.dgrdSample.DataMember = "MyTable";
this.dgrdSample.DataSource = ds;

txtMainText.DataBindings.Add(new Binding("Text", ds,
"MyTable.MyTextField"));

if not ask againg

MajorTom

Nevyn Twyll said:
I tried that and it didn't seem to work. It binds it to the first value in
the list, but doesn't change when the datagrid changes rows.

I have:

DataSet ds = sqlconnection.ExecuteDataSet(...)
this.dgrdSample.DataSource = ds.Tables[0];
ds.Tables[0].TableName = "MyTable";
txtMainText.DataBindings.Add(new Binding("Text", ds,
"MyTable.MyTextField"));

help?

William Ryan eMVP said:
Set the databindings of the text box to the same source
On a Windows form, I get a dataset and bind it to a datagrid.
I also want to have a textbox on that form I want to show the full
text
of
a
column in the currently selected row of the datagrid.

How do I bind a textbox to show the contents of a column in the currently
selected row of a datagrid?

Help?

- nevyn
 

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