binding textbox to dataset - newbie question

M

mal

Hi,
I have binded a textbox at runtime to a dataset in the form load using:

textBox2.DataBindings.Add("Text",dataSet41,"status.name");

I have a datagrid that is bound to the same dataset and
I want the textbox to display the "name" column of whatever row is
currently selected on the datagrid.
The textbox displays the correct value from the first row (name) of the
datagrid on loading, but my prob is that it wont update (the first value
stays there) as i change the selected row on the datagrid.
Plz help this one has been annoying me for a while and I have searched
hard on msn, google newsgroups etc.
Thanks for any help.
Mal
 
M

Morten Wennevik

Hi mal,

Your textbox is bound to the dataset not the datagrid. It will display the first value in the "name" column from the datatable "status". Any changes to the textbox will be stored in the dataset.

Selecting a different row in the datagrid won't have any effect in the databinding.

I'm not sure you can directly bind the currently selected row to a textbox and have it display a certain column from that row.

You will probably have to manually update the content of the textbox when you select a new row. Add a Update button to update the content of the textbox back to the datagrid.
 
P

Phil Jenson

Mal,
but my prob is that it wont update (the first value stays there) as i
change the selected row on the datagrid.

What you are doing seems correct. Have you tried calling the
EndCurrentEdit() method of the currency manager prior to changing row within
the DataGrid?

Phil...
 
M

mal

Thanks for the help guys but I finally FINALLY worked it out by myself.
Just one of those things, sorry to waste your time on it but i thought i
would let you know..
I had:
textBox2.DataBindings.Add("Text",dataSet41,"status.name");
What i have now:
textBox2.DataBindings.Add("Text", dataSet41.status, "name");
doh!

Mal
 

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