472,353 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

How to save textbox.text to the dataset when it's bound to datagri

Hi, I have a window based program. One of the form has several textboxes and
a datagrid. The textboxes are bind to the same dataset table as the datagrid
and the text changes to reflect different row selected in the datagrid.

I want to save the changes that user make in the textboxes when they select
a different row in the datagrid. I tried capturing the textbox.text at
datagrid's CurrentCellChanged event but by then the textbox.text is lost
already becuase the binding is to the new currently selected row.

private void VListing_CurrentCellChanged(object sender, System.EventArgs e)
{
if(Changed)
{
dsVehicle.Tables["vehDetail"].Rows[prevRow]["Model"] = test;
prevRow = VListing.CurrentCell.RowNumber;
UpdateDataSet(dsVehicle);
}
Changed = false;
}

private void txtVModel_Validated(object sender, System.EventArgs e)
{
test = txtVModel.Text.ToString();

}
I tried capturing the textbox.text at textbox validated event and then
assign that to the dataset.tables.rows[col] and then update the database but
that isn't working either. I did capter the textbox.text but the assignment
to the dataset and update to the database is not working. Can someone tell
me what's the best way to do this? Or point me to an example?

Thanks, Alpha
Nov 17 '05 #1
2 4681
Hi Alpha,

My understanding is that if you change the text in a bound text box and then
move the input focus elsewhere, the change must be automatically propagated
to the underlying data source. So your ultimate goal might be how to force
the text box to lose input focus when the grid is being clicked (if that
does not happen automatically).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
Hi, I have a window based program. One of the form has several textboxes
and
a datagrid. The textboxes are bind to the same dataset table as the
datagrid
and the text changes to reflect different row selected in the datagrid.

I want to save the changes that user make in the textboxes when they
select
a different row in the datagrid. I tried capturing the textbox.text at
datagrid's CurrentCellChanged event but by then the textbox.text is lost
already becuase the binding is to the new currently selected row.

private void VListing_CurrentCellChanged(object sender, System.EventArgs
e)
{
if(Changed)
{
dsVehicle.Tables["vehDetail"].Rows[prevRow]["Model"] = test;
prevRow = VListing.CurrentCell.RowNumber;
UpdateDataSet(dsVehicle);
}
Changed = false;
}

private void txtVModel_Validated(object sender, System.EventArgs e)
{
test = txtVModel.Text.ToString();

}
I tried capturing the textbox.text at textbox validated event and then
assign that to the dataset.tables.rows[col] and then update the database
but
that isn't working either. I did capter the textbox.text but the
assignment
to the dataset and update to the database is not working. Can someone
tell
me what's the best way to do this? Or point me to an example?

Thanks, Alpha


Nov 17 '05 #2
The form has several textboxes on the top half and the bottom has a datagrid.
The textboxes are bind to the same dataset table as the datagrid so that
when user selects different row in the DG the textboxes would display the
data related to that row.

I want to save the changes that users make to the textboxes when they either
click on another row on the DG or click OK button. When I use the following
code doesn't it change the dataset table for that row?
dsVehicle.Tables["vehDetail"].Rows[prevRow]["Model"] = test;

I then call Updatedataset() to update the database. But none of this is
working.

private void UpdateDataSet(DataSet myDataSet)
{
// Check for changes with the HasChanges method first.
if(!myDataSet.HasChanges(DataRowState.Modified)) return;
// Create temporary DataSet variable.
DataSet xDataSet;
// GetChanges for modified rows only.
xDataSet = myDataSet.GetChanges(DataRowState.Modified);
// Check the DataSet for errors.
if(xDataSet.HasErrors)
{
MessageBox.Show("There is an error getting the changed data.", "VMS -
Cycle item error.", MessageBoxButtons.OK);
}
else
{
// After fixing errors, update the data source with the DataAdapter
// used to create the DataSet.
// if (bool oleDbConnection1.Close())
sdaVehicle.Update(dsVehicle, "VehDetail");
}
}

"Dmytro Lapshyn [MVP]" wrote:
Hi Alpha,

My understanding is that if you change the text in a bound text box and then
move the input focus elsewhere, the change must be automatically propagated
to the underlying data source. So your ultimate goal might be how to force
the text box to lose input focus when the grid is being clicked (if that
does not happen automatically).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
Hi, I have a window based program. One of the form has several textboxes
and
a datagrid. The textboxes are bind to the same dataset table as the
datagrid
and the text changes to reflect different row selected in the datagrid.

I want to save the changes that user make in the textboxes when they
select
a different row in the datagrid. I tried capturing the textbox.text at
datagrid's CurrentCellChanged event but by then the textbox.text is lost
already becuase the binding is to the new currently selected row.

private void VListing_CurrentCellChanged(object sender, System.EventArgs
e)
{
if(Changed)
{
dsVehicle.Tables["vehDetail"].Rows[prevRow]["Model"] = test;
prevRow = VListing.CurrentCell.RowNumber;
UpdateDataSet(dsVehicle);
}
Changed = false;
}

private void txtVModel_Validated(object sender, System.EventArgs e)
{
test = txtVModel.Text.ToString();

}
I tried capturing the textbox.text at textbox validated event and then
assign that to the dataset.tables.rows[col] and then update the database
but
that isn't working either. I did capter the textbox.text but the
assignment
to the dataset and update to the database is not working. Can someone
tell
me what's the best way to do this? Or point me to an example?

Thanks, Alpha


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Paul Slavin | last post by:
I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this?? any...
2
by: bisoft | last post by:
Hi I have a textbox which is bound to a typed dataset. The type of the data is int. Now I'd like to programmatically change the value in this...
4
by: John Rose | last post by:
I have one databound TextBox on a page with one button. The TextBox loads the correct SQL record data but typing a new string into the Textbox...
3
by: matthew schouppe | last post by:
I have a datagrid with two columns, the first a normal bound column, the second is a template column created from a bound column. For the...
2
by: | last post by:
Hi all, I need to format screen output for a textbox that's bound to a datasource. I know how to format the data in a plain old string, but in...
6
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. ...
2
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created...
2
by: toddw607 | last post by:
Hi all! I am attempting to bring an SQL Server table into ASP.NET using the datagrid . I have set all cells to be a text box by which the...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.