BindingManagerBase的应用
代码如下:
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Text;
7using System.Windows.Forms;
8using Traffic_SQLDAL;
9using Traffic_SQLDAL.TrafficDSTableAdapters;
10using Traffic_BLL;
11using Traffic_Model;
12
13namespace WinControlLib
14{
15 public partial class UserControl3 : UserControl
16 {
17 BindingManagerBase bManager;
18 public UserControl3()
19 {
20 InitializeComponent();
21
22
23
24 List<MapIconHistoryInfo> infos = MapIconHistoryBLL.J_M_GetHistotyNoteByMapIconID(13);
25
26 //数据源用infos ********************************************
27 //textBox1.DataBindings.Add("Text", infos, "ID");
28 //textBox2.DataBindings.Add("Text", infos, "Deadline");
29
30 //bManager = this.BindingContext[infos];
31
32 //*******************************************************
33 //数据源用 bindingSource1
34 this.bindingSource1.DataSource = infos;
35 textBox1.DataBindings.Add("Text", bindingSource1, "ID");
36 textBox2.DataBindings.Add("Text", bindingSource1, "Deadline");
37
38 bManager = this.BindingContext[bindingSource1];
39 }
40
41 private void button1_Click(object sender, EventArgs e)
42 {
43 bManager.Position -= 1;
44 }
45
46 private void button2_Click(object sender, EventArgs e)
47 {
48 bManager.Position += 1;
49 }
50 }
51}
52
53
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Text;
7using System.Windows.Forms;
8using Traffic_SQLDAL;
9using Traffic_SQLDAL.TrafficDSTableAdapters;
10using Traffic_BLL;
11using Traffic_Model;
12
13namespace WinControlLib
14{
15 public partial class UserControl3 : UserControl
16 {
17 BindingManagerBase bManager;
18 public UserControl3()
19 {
20 InitializeComponent();
21
22
23
24 List<MapIconHistoryInfo> infos = MapIconHistoryBLL.J_M_GetHistotyNoteByMapIconID(13);
25
26 //数据源用infos ********************************************
27 //textBox1.DataBindings.Add("Text", infos, "ID");
28 //textBox2.DataBindings.Add("Text", infos, "Deadline");
29
30 //bManager = this.BindingContext[infos];
31
32 //*******************************************************
33 //数据源用 bindingSource1
34 this.bindingSource1.DataSource = infos;
35 textBox1.DataBindings.Add("Text", bindingSource1, "ID");
36 textBox2.DataBindings.Add("Text", bindingSource1, "Deadline");
37
38 bManager = this.BindingContext[bindingSource1];
39 }
40
41 private void button1_Click(object sender, EventArgs e)
42 {
43 bManager.Position -= 1;
44 }
45
46 private void button2_Click(object sender, EventArgs e)
47 {
48 bManager.Position += 1;
49 }
50 }
51}
52
53
运行效果: