I new that BindingSource's AddingNew event can handle all default value assignment, but was so frustrated that I could not find any articles/tutorials which guided me on how to use it. Although MSDN had description, but it did not have samples on how to use it. However, with few long hour searches I came to a source which enlighted me on how to use this event.
A sample code looks like this:
private void branchBindingSource_AddingNew(object sender, AddingNewEventArgs e) { //// Get data table view DataView dataTableView = branchBindingSource.List as DataView; //// Create row from view DataRowView rowView = dataTableView.AddNew(); rowView["BranchID"] = -1; rowView["BranchCode"] = "001"; rowView["BranchDescription"] = "002"; //// Set New row e.NewObject = rowView; branchBindingSource.MoveLast(); }
11 comments:
This is an outstanding bit of work that will save me countless hours of development time. THANK YOU!!!
thanks for taking the time to post this, it's been very helpful for me
Nice post all the information of the place there in the blog but it should have also contains some pictures or images of the place which look more attractive
Awesome! You just saved me from spending another fruitless hour trying to figure this out!
Thanks for that. Very useful.
Thank you, thank you, thank you!
Thank you so much! Still getting used to .NET, there is so much to it and finding the 'right' way to do things can be confusing!
Thank you, thank you, thank you! My headache is gone.
Thank you, was looking hours for this !!!!
Another one here who was very happy to find this page! It looks like you haven't updated the blog recently. I hope everything is well with you!
Wow, eight years later, and this is still a VERY useful post. I've actually used it, forgotten about it, and then searched for it again when I needed it again.
Post a Comment