DataBinding Protected Sub BindControls() ' Create two Binding objects for the first two TextBox ' controls. The data-bound property for both controls ' is the Text property. The data source is a DataSet ' (ds). The data member is specified by a navigation ' path in the form : TableName.ColumnName. textBox1.DataBindings.Add _ (New Binding("Text", ds, "customers.custName")) textBox2.DataBindings.Add _ (New Binding("Text", ds, "customers.custID")) ' Bind the DateTimePicker control by adding a new Binding. ' The data member of the DateTimePicker is specified by a ' navigation path in the form: TableName.RelationName.ColumnName. DateTimePicker1.DataBindings.Add _ (New Binding("Value", ds, "customers.CustToOrders.OrderDate")) ' Create a new Binding using the DataSet and a ' navigation path(TableName.RelationName.ColumnName). ' Add event delegates for the Parse and Format events to ' the Binding object, and add the object to the third ' TextBox control's BindingsCollection. The delegates ' must be added before adding the Binding to the ' collection; otherwise, no formatting occurs until ' the Current object of the BindingManagerBase for ' the data source changes. Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount") AddHandler b.Parse, AddressOf CurrencyStringToDecimal AddHandler b.Format, AddressOf DecimalToCurrencyString textBox3.DataBindings.Add(b) ' Bind the fourth TextBox to the Value of the ' DateTimePicker control. This demonstrates how one control ' can be bound to another. textBox4.DataBindings.Add("Text", DateTimePicker1, "Value") Dim bmText As BindingManagerBase = Me.BindingContext(DateTimePicker1) ' Print the Type of the BindingManagerBase, which is ' a PropertyManager because the data source ' returns only a single property value. Console.WriteLine(bmText.GetType().ToString()) ' Print the count of managed objects, which is 1. Console.WriteLine(bmText.Count) ' Get the BindingManagerBase for the Customers table. bmCustomers = Me.BindingContext(ds, "Customers") ' Print the Type and count of the BindingManagerBase. ' Because the data source inherits from IBindingList, ' it is a RelatedCurrencyManager (derived from CurrencyManager). Console.WriteLine(bmCustomers.GetType().ToString()) Console.WriteLine(bmCustomers.Count) ' Get the BindingManagerBase for the Orders of the current ' customer using a navigation path: TableName.RelationName. bmOrders = Me.BindingContext(ds, "customers.CustToOrders") End Sub in referenze: Microsoft.VisualBasic.Compatibility System System.Data System.Drawing System.Windows.Forms System.Xml Option Strict Off Option Explicit On Friend Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load 'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' If Dir(My.Application.Info.DirectoryPath & "\Pippo", FileAttribute.Directory) = "" Then MkDir(My.Application.Info.DirectoryPath & "\Pippo") Else ChDir(My.Application.Info.DirectoryPath & "\Pippo") End If 'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' If Dir(My.Application.Info.DirectoryPath & "\Pippo.text") = "" Then FileOpen(1, My.Application.Info.DirectoryPath & "\Pippo.text", OpenMode.Output) PrintLine(1, "Ciao") PrintLine(1, "-----") FileClose(1) End If 'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' Dim stringa As String = "" Dim Mstringa As String = "" If Dir(My.Application.Info.DirectoryPath & "\Pippo.text") = "" Then FileOpen(1, My.Application.Info.DirectoryPath & "\Pippo.text", OpenMode.Input) stringa = LineInput(1) Mstringa &= stringa stringa = LineInput(1) Mstringa &= stringa FileClose(1) MsgBox(Mstringa, MsgBoxStyle.Critical, "OK al cazzo") End If 'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' If Dir(My.Application.Info.DirectoryPath & "\Pippo.text") <> "" Then Rename(My.Application.Info.DirectoryPath & "\Pippo.text", My.Application.Info.DirectoryPath & "\Pippo.txt2") End If End Sub End Class |