forked from jaysonragasa/MultiRDPClient.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataBinding.cs
More file actions
108 lines (103 loc) · 2.88 KB
/
DataBinding.cs
File metadata and controls
108 lines (103 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace CommonTools
{
public class MyBindingSource : System.Windows.Forms.BindingSource
{
public event EventHandler ValueChanged;
public void RaiseValueChanged(object sender)
{
if (ValueChanged != null)
ValueChanged(sender, null);
}
}
public class BindingWithNotify : System.Windows.Forms.Binding
{
public BindingWithNotify(string propertyName, object dataSource, string dataMember) : base(propertyName, dataSource, dataMember, true)
{
}
protected override void OnBindingComplete(BindingCompleteEventArgs e)
{
base.OnBindingComplete(e);
this.Control.Validating += new CancelEventHandler(Control_Validating);
}
void Control_Validating(object sender, CancelEventArgs e)
{
WriteNotifyIfChanged();
}
public void WriteNotify()
{
WriteValue();
NotifyChanged();
}
public void WriteNotifyIfChanged()
{
object dataobject = DataSource;
if (dataobject is ICurrencyManagerProvider)
dataobject = ((ICurrencyManagerProvider)dataobject).CurrencyManager.Current;
PropertyInfo info = PropertyUtil.GetNestedProperty(ref dataobject, BindingMemberInfo.BindingMember);
if (info != null)
{
object objBefore = info.GetValue(dataobject, null);
WriteValue();
object objAfter = info.GetValue(dataobject, null);
if (objBefore != null && objAfter != null && objBefore.Equals(objAfter) == false)
NotifyChanged();
ReadValue();
}
}
protected virtual void NotifyChanged()
{
MyBindingSource ds = DataSource as MyBindingSource;
if (ds != null)
ds.RaiseValueChanged(this);
}
protected override void OnParse(ConvertEventArgs cevent)
{
//base.OnParse(cevent);
//WriteNotifyIfChanged();
}
}
public class RadioButtonBinder : BindingWithNotify
{
public RadioButtonBinder(string propertyName, object dataSource, string dataMember) : base(propertyName, dataSource, dataMember)
{
}
protected override void OnFormat(ConvertEventArgs cevent)
{
MyRadioButton b = Control as MyRadioButton;
b.Checked = b.CheckedValue.Equals(cevent.Value);
}
protected override void OnParse(ConvertEventArgs cevent)
{
MyRadioButton b = Control as MyRadioButton;
if (b.Checked)
cevent.Value = b.CheckedValue;
}
}
public class NameObjectBinder : BindingWithNotify
{
public NameObjectBinder(string propertyName, object dataSource, string dataMember) : base(propertyName, dataSource, dataMember)
{
}
protected override void OnFormat(ConvertEventArgs cevent)
{
base.OnFormat(cevent);
}
protected override void OnParse(ConvertEventArgs cevent)
{
Console.WriteLine("OnParse ({0},{1})", cevent.DesiredType, cevent.Value);
if (cevent.Value == DBNull.Value)
{
}
//base.OnParse(cevent);
cevent.Value = 1;
}
}
}