The bindingsource changes are automatically added when they are saved, such as the modifier.

Source: Internet
Author: User
Today's exploitation Bindingsource is bound to the control. Program To automatically add the modifier and modify the date when saving the file. This action does not require operator interference. The difficulty is that the rows are modified during the determination and storage.
After testing, it is found that the currentchanged event is triggered only after it occurs.The endedit () Operation of the current item of bindingsource, that is, the endedit () operation cannot be directly triggered after the value is modified in the control. At the same time, the status of endedit () is changed to datarowstate. modified. Code Medium The data source of bindingsource is This. rhxsgldataset. t_zhenceline. 1   Private   Void Ubtline_btsaveclick ( Object Sender, system. eventargs E)
2 {
3 Try
4 {
5 This . Validate ();
6 This . T_zhencelinebindingsource.endedit ();
7 /**/ ///Update xgid and xgdate, and select the updated row through rowstate. Note that it must be changed to datarowstate. Modified after endedit.
8 Int I =   0 ;
9 Int Linecount =   0 ;
10 If ( This . Rhxsgldataset. t_zhenceline ! =   Null )
11 Linecount =   This . Rhxsgldataset. t_zhenceline.rows.count;
12 While (I < Linecount)
13 {
14 If ( This . Rhxsgldataset. t_zhenceline.rows [I]. rowstate = Datarowstate. modified)
15 {
16 This . Rhxsgldataset. t_zhenceline.rows [I] [ " Xgid " ] = My_classes.c_user.loginuserid;
17 This . Rhxsgldataset. t_zhenceline.rows [I] [ " Xgdate " ] = Datetime. now;
18 }
19
20 I = I +   1 ;
21 }
22
23 This . T_zhencelinetableadapter.update ( This . Rhxsgldataset. t_zhenceline );
24 MessageBox. Show ( " Saved successfully! " );
25
26 }
27 Catch (Exception ex)
28 {
29MessageBox. Show (ex. Message );
30
31}
32 }

pay attention to the above content. The bindingsource currentitemchanged event is also triggered after row and endedit (). After the current item is moved in the interface operation, this is triggered only when you navigate to the next line or select other rows. You can also manually endedit () to trigger this event after modifying the value in the control. For example, you can add a button to write bindingsource. endedit () to test that the currentitemchanged event is triggered.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.