Solved

.AddNew record without clearing the form...

Posted on 2006-06-17
5
335 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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