473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 4796
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 answers appreciated, as to due to the underlying...
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 textbox (i.e. textBox1.text = "123"). For some...
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 fails to change the DataSet. Any ideas? There must...
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 ItemTemplate of the Template Column, I removed the label...
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 this case I'm not sure where to "sneak" in there...
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 the fields to a textbox. After setting up the...
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.. Basically, on my form I have a DataGridView, it's got...
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 strongly typed data adapters and datasets. The...
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 user can just click on and edit the cell. I have a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.