Question new prefilled item in databinding

fabiocrj

Member
Joined
Mar 15, 2011
Messages
10
Programming Experience
Beginner
Hi all,
I have many bounded items in a Windows Form. When user fill the fields (textboxes, checkboxes, etc) and save then, i want the user to have the option to "save as new item". So, he only need to change the fields that are different from the last item.
Here is an example:
The form have 4 itens: id, model, serial number and description. If the model and description are the same, only the filed "serial number" would have to be changed.
When i use ListaBindingSource.AddNew(), all fields will be blanked. I want to copy all the items when i add a new item in the bindingsource
How can i do it?

thanks in advance
 
Save them to variables before commiting the save and in the Add event (where it blanks everything for entry) set your controls to what their variables hold.

This could be a simple private class with a property for each field you want to keep.
 
Save them to variables before commiting the save and in the Add event (where it blanks everything for entry) set your controls to what their variables hold.

This could be a simple private class with a property for each field you want to keep.

Thank you for your answer. The problem is that, by doing this way, i´ll have to save each field to a variable. In my real Form, there will be more than 100 fields, and it will get very cumbersome doing this...
 
You haven't got anything bounded. "Bounded" is the past tense of "bound", e.g. my dog was so happy to see me that it bounded across the garden and jumped on me. In this case the word is simply "bound', which is the past tense of "bind", e.g. the kidnapper bound my hands behind my back.

If it's a type of your own creation then you can implement ICloneable and add a Clone method, which will allow you to use MemberwiseClone internally to do the heavy lifting.
 
You haven't got anything bounded. "Bounded" is the past tense of "bound", e.g. my dog was so happy to see me that it bounded across the garden and jumped on me. In this case the word is simply "bound', which is the past tense of "bind", e.g. the kidnapper bound my hands behind my back.

If it's a type of your own creation then you can implement ICloneable and add a Clone method, which will allow you to use MemberwiseClone internally to do the heavy lifting.

Thank you for your correction.... As you can see, english is not my native language
I don´t know how to use ICloneable, so i´ll study it and try implement it. Then i can post a feedback here.

Thank you
 
Hi all,


I´ve found the solution. I don´t know if it´s the best approach, but it works:
VB.NET:
Me.MyBindingSource.AddNew()
For Each c As DataColumn In MyDataSet.MyDatabase.Columns
      If Not c.Unique Then Me.MyBindingSource.Item(newRow)(c.ColumnName) = Me.MyBindingSource.Item(newRow - 1)(c.ColumnName)
Next
What do you think about it? Any idea to improve it?


Thank You
 
Back
Top