Solved

.AddNew record without clearing the form...

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculate number of nights between two dates 5 93
Input parameteres to DragOver 2 37
orderby list (from Json) 1 30
C# DataTable (in memory) vs SQL Lookups 4 36
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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