forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.vb
59 lines (46 loc) · 1.66 KB
/
source.vb
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
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Protected textBox1 As TextBox
' <Snippet1>
Private Sub BindTextBoxProperties()
' Clear the collection before adding new Binding objects.
textBox1.DataBindings.Clear()
' Create a DataTable containing Color objects.
Dim t As DataTable = MakeTable()
' Bind the Text, BackColor, and ForeColor properties
' to columns in the DataTable.
textBox1.DataBindings.Add("Text", t, "Text")
textBox1.DataBindings.Add("BackColor", t, "BackColor")
textBox1.DataBindings.Add("ForeColor", t, "ForeColor")
End Sub
Private Function MakeTable() As DataTable
' Create a DataTable with three columns.
' Two of the columns contain Color objects.
Dim t As New DataTable("Control")
t.Columns.Add("BackColor", GetType(Color))
t.Columns.Add("ForeColor", GetType(Color))
t.Columns.Add("Text")
' Add three rows to the table.
Dim r As DataRow
r = t.NewRow()
r("BackColor") = Color.Blue
r("ForeColor") = Color.Yellow
r("Text") = "Yellow on Blue"
t.Rows.Add(r)
r = t.NewRow()
r("BackColor") = Color.White
r("ForeColor") = Color.Green
r("Text") = "Green on white"
t.Rows.Add(r)
r = t.NewRow()
r("BackColor") = Color.Orange
r("ForeColor") = Color.Black
r("Text") = "Black on Orange"
t.Rows.Add(r)
Return t
End Function
' </Snippet1>
End Class