Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.AddNew record without clearing the form...

Posted on 2006-06-17
5
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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