Textbox bind to datagrid but text doesn't change when selection ch

G

Guest

I have several textboxes that I need to chang the text when the selection row
is changed in a datagrid. I have the following code. This textbox displayes
the initial selection but when I click on different rows in the datagrid, the
textbox content doesn't change to reflect the change. How can I address
this?

Also, If the user change the text in the textbox then how do I refesh the
display in the datagrid to reflect the changes?

Thanks, Alpha
 
N

Nicholas Paldino [.NET/C# MVP]

Alpha,

It seems like you either have separate binding contexts, or that you are
binding to different data sources. First off, are the textboxes and data
grid in the same form? If not, then you have to create a binding context
and have the forms share it.

Second, how are you setting the data source in the bindings and the data
source in the grid? If you have a data set with a table, "Table", for
example, the following two are NOT the same:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Table";

// Is not the same as.
dataGrid.DataSource = dataSet.Tables["Table"];

Also, are you using any views, by chance? Are you binding to different
views?
 
G

Guest

VListing is the datagrid and it's datasource is a dataset table:
VListing.SetDataBinding(dsVehicle, "VehDetail");

The textbox is only bind to the datagrid through the same dataset table:
txtVName.DataBindings.Add("Text", dsVehicle.Tables["vehDetail"], "VName");

I don't have any view created for this. These controls are all on the same
form.

Thank you, Alpha

Nicholas Paldino said:
Alpha,

It seems like you either have separate binding contexts, or that you are
binding to different data sources. First off, are the textboxes and data
grid in the same form? If not, then you have to create a binding context
and have the forms share it.

Second, how are you setting the data source in the bindings and the data
source in the grid? If you have a data set with a table, "Table", for
example, the following two are NOT the same:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Table";

// Is not the same as.
dataGrid.DataSource = dataSet.Tables["Table"];

Also, are you using any views, by chance? Are you binding to different
views?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
I have several textboxes that I need to chang the text when the selection
row
is changed in a datagrid. I have the following code. This textbox
displayes
the initial selection but when I click on different rows in the datagrid,
the
textbox content doesn't change to reflect the change. How can I address
this?

Also, If the user change the text in the textbox then how do I refesh the
display in the datagrid to reflect the changes?

Thanks, Alpha
 
N

Nicholas Paldino [.NET/C# MVP]

Alpha,

That is the problem. You are binding to dsVehicle.Tables["vehDetail"]
in the bindings, and to the data set in the vlisting.

Change the code to set the data bindings in the VListing to:

VListing.SetDataBinding(dsVehicle.Tables["vehDetail"], null);

And it should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
VListing is the datagrid and it's datasource is a dataset table:
VListing.SetDataBinding(dsVehicle, "VehDetail");

The textbox is only bind to the datagrid through the same dataset table:
txtVName.DataBindings.Add("Text", dsVehicle.Tables["vehDetail"], "VName");

I don't have any view created for this. These controls are all on the
same
form.

Thank you, Alpha

Nicholas Paldino said:
Alpha,

It seems like you either have separate binding contexts, or that you
are
binding to different data sources. First off, are the textboxes and data
grid in the same form? If not, then you have to create a binding context
and have the forms share it.

Second, how are you setting the data source in the bindings and the
data
source in the grid? If you have a data set with a table, "Table", for
example, the following two are NOT the same:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Table";

// Is not the same as.
dataGrid.DataSource = dataSet.Tables["Table"];

Also, are you using any views, by chance? Are you binding to
different
views?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
I have several textboxes that I need to chang the text when the
selection
row
is changed in a datagrid. I have the following code. This textbox
displayes
the initial selection but when I click on different rows in the
datagrid,
the
textbox content doesn't change to reflect the change. How can I
address
this?

Also, If the user change the text in the textbox then how do I refesh
the
display in the datagrid to reflect the changes?

Thanks, Alpha
 
G

Guest

Hummmm, like magic, it's working just great! I don't quite understand. I
followed the databinding sytax for the datagrid, to put datasource as dataset
and the datamember as the table. You have it all specified in the
datasource.

So I guess the textbox binding only looks at the datagrid's datasource and
not the datamember, is that correct? And that's the source of my problem?
Hummmm.... Thank you so much. I wouldn't have been able to figure that one
out myslef for sure.

Nicholas Paldino said:
Alpha,

That is the problem. You are binding to dsVehicle.Tables["vehDetail"]
in the bindings, and to the data set in the vlisting.

Change the code to set the data bindings in the VListing to:

VListing.SetDataBinding(dsVehicle.Tables["vehDetail"], null);

And it should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
VListing is the datagrid and it's datasource is a dataset table:
VListing.SetDataBinding(dsVehicle, "VehDetail");

The textbox is only bind to the datagrid through the same dataset table:
txtVName.DataBindings.Add("Text", dsVehicle.Tables["vehDetail"], "VName");

I don't have any view created for this. These controls are all on the
same
form.

Thank you, Alpha

Nicholas Paldino said:
Alpha,

It seems like you either have separate binding contexts, or that you
are
binding to different data sources. First off, are the textboxes and data
grid in the same form? If not, then you have to create a binding context
and have the forms share it.

Second, how are you setting the data source in the bindings and the
data
source in the grid? If you have a data set with a table, "Table", for
example, the following two are NOT the same:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Table";

// Is not the same as.
dataGrid.DataSource = dataSet.Tables["Table"];

Also, are you using any views, by chance? Are you binding to
different
views?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have several textboxes that I need to chang the text when the
selection
row
is changed in a datagrid. I have the following code. This textbox
displayes
the initial selection but when I click on different rows in the
datagrid,
the
textbox content doesn't change to reflect the change. How can I
address
this?

Also, If the user change the text in the textbox then how do I refesh
the
display in the datagrid to reflect the changes?

Thanks, Alpha
 
N

Nicholas Paldino [.NET/C# MVP]

Alpha,

It does look at both the data source and the data member, but it uses
those two things together to determine if the data source is the same.
Since the data source for one was the table, and the data source for the
other was the data set (while the data member was null and the name of the
table respectively), it considers the data sources separate.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
Hummmm, like magic, it's working just great! I don't quite understand. I
followed the databinding sytax for the datagrid, to put datasource as
dataset
and the datamember as the table. You have it all specified in the
datasource.

So I guess the textbox binding only looks at the datagrid's datasource and
not the datamember, is that correct? And that's the source of my problem?
Hummmm.... Thank you so much. I wouldn't have been able to figure that
one
out myslef for sure.

Nicholas Paldino said:
Alpha,

That is the problem. You are binding to
dsVehicle.Tables["vehDetail"]
in the bindings, and to the data set in the vlisting.

Change the code to set the data bindings in the VListing to:

VListing.SetDataBinding(dsVehicle.Tables["vehDetail"], null);

And it should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
VListing is the datagrid and it's datasource is a dataset table:
VListing.SetDataBinding(dsVehicle, "VehDetail");

The textbox is only bind to the datagrid through the same dataset
table:
txtVName.DataBindings.Add("Text", dsVehicle.Tables["vehDetail"],
"VName");

I don't have any view created for this. These controls are all on the
same
form.

Thank you, Alpha

:

Alpha,

It seems like you either have separate binding contexts, or that
you
are
binding to different data sources. First off, are the textboxes and
data
grid in the same form? If not, then you have to create a binding
context
and have the forms share it.

Second, how are you setting the data source in the bindings and
the
data
source in the grid? If you have a data set with a table, "Table", for
example, the following two are NOT the same:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Table";

// Is not the same as.
dataGrid.DataSource = dataSet.Tables["Table"];

Also, are you using any views, by chance? Are you binding to
different
views?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have several textboxes that I need to chang the text when the
selection
row
is changed in a datagrid. I have the following code. This textbox
displayes
the initial selection but when I click on different rows in the
datagrid,
the
textbox content doesn't change to reflect the change. How can I
address
this?

Also, If the user change the text in the textbox then how do I
refesh
the
display in the datagrid to reflect the changes?

Thanks, Alpha
 
G

Guest

Thank you.

Nicholas Paldino said:
Alpha,

It does look at both the data source and the data member, but it uses
those two things together to determine if the data source is the same.
Since the data source for one was the table, and the data source for the
other was the data set (while the data member was null and the name of the
table respectively), it considers the data sources separate.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alpha said:
Hummmm, like magic, it's working just great! I don't quite understand. I
followed the databinding sytax for the datagrid, to put datasource as
dataset
and the datamember as the table. You have it all specified in the
datasource.

So I guess the textbox binding only looks at the datagrid's datasource and
not the datamember, is that correct? And that's the source of my problem?
Hummmm.... Thank you so much. I wouldn't have been able to figure that
one
out myslef for sure.

Nicholas Paldino said:
Alpha,

That is the problem. You are binding to
dsVehicle.Tables["vehDetail"]
in the bindings, and to the data set in the vlisting.

Change the code to set the data bindings in the VListing to:

VListing.SetDataBinding(dsVehicle.Tables["vehDetail"], null);

And it should work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VListing is the datagrid and it's datasource is a dataset table:
VListing.SetDataBinding(dsVehicle, "VehDetail");

The textbox is only bind to the datagrid through the same dataset
table:
txtVName.DataBindings.Add("Text", dsVehicle.Tables["vehDetail"],
"VName");

I don't have any view created for this. These controls are all on the
same
form.

Thank you, Alpha

:

Alpha,

It seems like you either have separate binding contexts, or that
you
are
binding to different data sources. First off, are the textboxes and
data
grid in the same form? If not, then you have to create a binding
context
and have the forms share it.

Second, how are you setting the data source in the bindings and
the
data
source in the grid? If you have a data set with a table, "Table", for
example, the following two are NOT the same:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Table";

// Is not the same as.
dataGrid.DataSource = dataSet.Tables["Table"];

Also, are you using any views, by chance? Are you binding to
different
views?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have several textboxes that I need to chang the text when the
selection
row
is changed in a datagrid. I have the following code. This textbox
displayes
the initial selection but when I click on different rows in the
datagrid,
the
textbox content doesn't change to reflect the change. How can I
address
this?

Also, If the user change the text in the textbox then how do I
refesh
the
display in the datagrid to reflect the changes?

Thanks, Alpha
 

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