By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,926 Members | 1,839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,926 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.