Solved

.AddNew record without clearing the form...

Posted on 2006-06-17
5
331 Views
Last Modified: 2011-10-03
Hello I have a form that is a bunch of combos/texboxes etc and is used strictly for data entry, the customer would like to have the ability after saving the record to have the data stay on the screen, because most of the time the data is nearly identical - strange I know believe me :)

Anyway the form is bound to a typed dataset and after the form is saved, I call a BindingContext...AddNew() to add a new record to the dataset, works beatiful, great.

is there a setting or override to prevent the data from clearing when this method is called?

I have been pulling my hair out for the last week, i.e. saving the dataset to xml, then reloading it back in - major problems there, anyways I would appreciate the help.

I hope some of you have run into this before and have a solution before, it seems sooo damn easy to.

Thanks Josh
0
Comment
Question by:joshcrosby
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
ID: 16934262
You can copy the row instead of just creating a new one. Here is how you can do this:

DataSet1.DataTable1Row row = this.dataSet11.DataTable1.NewDataTable1Row();
row.Column1 = "val1";
row.Column2 = "val2";
this.dataSet11.DataTable1.AddDataTable1Row(row);

object[] items = new object[row.ItemArray.Length];
row.ItemArray.CopyTo(items, 0);
DataSet1.DataTable1Row newRow = (DataSet1.DataTable1Row)this.dataSet11.DataTable1.Rows.Add(items);
0
 
LVL 5

Expert Comment

by:pgloor
ID: 16934288
I don't know about your scenario, but in a similar situation with standard .NET 2.0 BindingSource and BindingNavigator I did something like the following in C#:

1. Added a private field to temporarily store the old value to my code.

  // Private field to keep the previous value
  private string oldValue = "";

2. Added an AddingNew event to my BindingSource with the following code

  // Remember the old value
  oldValue = valueTextBox.Text; // Assuming the name of the input text box is valueTextBox

3. Added a Click event to the Add New Item button of my Binding Navigator with the following code

  // Assign the stored value to the text box
  valueTextBox.Text = oldValue ; // Assuming the name of the input text box is valueTextBox

You should be able to do something similar. It's just a question to finding the right event.

Peter
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 16934316
pgloor: if you have 100 text boxes on a form, it's too much work. It is also a source of error if a new text box is added
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now