Article ID: 894501
Article Last Modified on 5/11/2007
APPLIES TO
- Microsoft Visual Studio .NET 2003 Professional Edition
- Microsoft Visual Studio .NET 2003 Enterprise Architect
- Microsoft Visual Studio .NET 2003 Enterprise Developer
- Microsoft Visual Studio .NET 2002 Professional Edition
- Microsoft Visual Studio .NET 2002 Enterprise Architect
- Microsoft Visual Studio .NET 2002 Enterprise Developer
- Microsoft Visual Basic 2005
Notice
SYMPTOMS
When a ComboBox control is bound to a table field and that table field value is null in Microsoft Visual Studio 2005, in Microsoft Visual Studio .NET 2003, or in Microsoft Visual Studio .NET 2002, the sequence of next and previous values may not correctly appear. For example, when the record that contains the null value is not the first record in the recordset and then the record that contains the null value is reached, the ComboBox control will display the first entry that was in the list.
WORKAROUND
To work around this issue, insert a non-null record that informs the user to perform an action in the lookup recordset. Set that record to be the default value for the ComboBox control.
MORE INFORMATION
Steps to reproduce the behavior
- Start Microsoft Visual Studio .NET 2002, Visual Studio .NET 2003, or Visual Studio 2005.
- On the File menu, click New, and then click Project.
- In the New Project window, click Visual Basic Projects, click Windows Application, name the application
ComboBoxBinding
, and then click OK.
Note In Visual Studio 2005, click Visual Basic under Project Types. In Design view of the Form1 form, rename the form to ComboBoxBinding, and then double-click and replace the autogenerated code with the following code example:
Imports System Imports System.ComponentModel Imports System.Drawing Imports System.Windows.Forms Imports System.Data Imports System.Data.SqlClient Namespace Microsoft.Samples.WinForms.VB.ComboBoxBinding Public Class ComboBoxBinding Inherits System.Windows.Forms.Form Shared Sub Main() Application.Run(New ComboBoxBinding()) End Sub Public Sub New() MyBase.New() ComboBoxBinding = Me ' This code is required by the Windows Forms Designer. InitializeComponent() ' Fill the DataSet. Dim con As SqlConnection = New SqlConnection("server=(local);Trusted_Connection=yes;database=northwind") Dim cmd As SqlDataAdapter = New SqlDataAdapter("Select * from Customers ", con) cmd.Fill(customersDataSet1, "Customers") Dim cmd1 As SqlDataAdapter = New SqlDataAdapter("Select StateCode, StateName from States", con) cmd1.Fill(DsStates1, "MyStates") ' Set up the Combobox control bindings. 'comboBoxUSState.DataSource = USStates ' Populate the list comboBoxUSState.DataSource = DsStates1.Tables("MyStates") comboBoxUSState.DisplayMember = "StateName" ' Define the field that will be displayed. comboBoxUSState.ValueMember = "StateCode" ' Define the field that will be used as the value. ' Bind the selected value of the ComboBox control to the Region field of the current ' Customer. comboBoxUSState.DataBindings.Add("SelectedValue", customersDataSet1, "Customers.Region") ' Set up the rest of the form bindings. textBoxID.DataBindings.Add("Text", customersDataSet1, "Customers.CustomerID") textBoxCity.DataBindings.Add("Text", customersDataSet1, "Customers.City") textBoxTitle.DataBindings.Add("Text", customersDataSet1, "Customers.ContactTitle") textBoxAddress.DataBindings.Add("Text", customersDataSet1, "Customers.Address") textBoxCompany.DataBindings.Add("Text", customersDataSet1, "Customers.CompanyName") textBoxContact.DataBindings.Add("Text", customersDataSet1, "Customers.ContactName") textBoxZip.DataBindings.Add("Text", customersDataSet1, "Customers.PostalCode") ' Handle position changing events for the DATA VCR panel. AddHandler Me.BindingContext(customersDataSet1, "Customers").PositionChanged, AddressOf customers_PositionChanged ' Set up the initial text for the DATA VCR panel. textBoxPosition.Text = "Record " + (Me.BindingContext(customersDataSet1, "Customers").Position + 1).ToString() + " of " + customersDataSet1.Customers.Count.ToString() ' Set the minimum form size. Me.MinimumSize = New Size(375, 361) End Sub ' When the MoveFirst button is clicked, set the position for the Customers table ' to the first record. Protected Sub buttonMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonMoveFirst.Click ' Unselect the previously selected comboBoxUSState value. Me.BindingContext(customersDataSet1, "Customers").Position = 0 End Sub ' When the MoveLast button is clicked, set the position for the Customers table ' to the last record. Protected Sub buttonMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonMoveLast.Click ' Unselect the previously selected comboBoxUSState value. Me.BindingContext(customersDataSet1, "Customers").Position = customersDataSet1.Customers.Count - 1 End Sub ' When the MoveNext button is clicked, increment the position for the Customers table. Protected Sub buttonMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonMoveNext.Click If Me.BindingContext(customersDataSet1, "Customers").Position < customersDataSet1.Customers.Count - 1 Then ' Unselect the previously selected comboBoxUSState value. Me.BindingContext(customersDataSet1, "Customers").Position += 1 End If End Sub ' When the MovePrev button is clicked, decrement the position for the Customers table. Protected Sub buttonMovePrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonMovePrev.Click If Me.BindingContext(customersDataSet1, "Customers").Position > 0 Then ' Unselect the previously selected comboBoxUSState value. Me.BindingContext(customersDataSet1, "Customers").Position -= 1 End If End Sub ' The psition has changed. Update the DATA VCR panel. Protected Sub customers_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) textBoxPosition.Text = "Record " + (Me.BindingContext(customersDataSet1, "Customers").Position + 1).ToString() + " of " + customersDataSet1.Customers.Count.ToString() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub #Region " Windows Form Designer generated code " Private components As System.ComponentModel.Container Private WithEvents customersDataSet1 As Microsoft.Samples.WinForms.VB.ComboBoxBinding.Data.CustomersDataSet Private WithEvents textBoxZip As System.Windows.Forms.TextBox Private WithEvents comboBoxUSState As System.Windows.Forms.ComboBox Private WithEvents textBoxCity As System.Windows.Forms.TextBox Private WithEvents labelUSState As System.Windows.Forms.Label Private WithEvents labelZip As System.Windows.Forms.Label Private WithEvents labelCity As System.Windows.Forms.Label Private WithEvents textBoxPosition As System.Windows.Forms.TextBox Private WithEvents buttonMoveFirst As System.Windows.Forms.Button Private WithEvents buttonMovePrev As System.Windows.Forms.Button Private WithEvents buttonMoveNext As System.Windows.Forms.Button Private WithEvents buttonMoveLast As System.Windows.Forms.Button Private WithEvents textBoxCompany As System.Windows.Forms.TextBox Private WithEvents labelCompanyName As System.Windows.Forms.Label Private WithEvents textBoxAddress As System.Windows.Forms.TextBox Private WithEvents textBoxTitle As System.Windows.Forms.TextBox Private WithEvents textBoxContact As System.Windows.Forms.TextBox Private WithEvents textBoxID As System.Windows.Forms.TextBox Private WithEvents labelAddress As System.Windows.Forms.Label Private WithEvents labelContactTitle As System.Windows.Forms.Label Private WithEvents labelContact As System.Windows.Forms.Label Private WithEvents labelID As System.Windows.Forms.Label Private WithEvents panelVCRControl As System.Windows.Forms.Panel Private WithEvents ComboBoxBinding As System.Windows.Forms.Form Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection Friend WithEvents DsStates1 As dsStates Private Sub InitializeComponent() Me.labelCity = New System.Windows.Forms.Label() Me.buttonMoveNext = New System.Windows.Forms.Button() Me.customersDataSet1 = New Microsoft.Samples.WinForms.VB.ComboBoxBinding.Data.CustomersDataSet() Me.labelContact = New System.Windows.Forms.Label() Me.buttonMoveFirst = New System.Windows.Forms.Button() Me.textBoxID = New System.Windows.Forms.TextBox() Me.textBoxCity = New System.Windows.Forms.TextBox() Me.labelContactTitle = New System.Windows.Forms.Label() Me.labelCompanyName = New System.Windows.Forms.Label() Me.textBoxTitle = New System.Windows.Forms.TextBox() Me.textBoxPosition = New System.Windows.Forms.TextBox() Me.labelUSState = New System.Windows.Forms.Label() Me.buttonMovePrev = New System.Windows.Forms.Button() Me.labelZip = New System.Windows.Forms.Label() Me.textBoxAddress = New System.Windows.Forms.TextBox() Me.textBoxCompany = New System.Windows.Forms.TextBox() Me.panelVCRControl = New System.Windows.Forms.Panel() Me.buttonMoveLast = New System.Windows.Forms.Button() Me.comboBoxUSState = New System.Windows.Forms.ComboBox() Me.labelAddress = New System.Windows.Forms.Label() Me.labelID = New System.Windows.Forms.Label() Me.textBoxContact = New System.Windows.Forms.TextBox() Me.textBoxZip = New System.Windows.Forms.TextBox() Me.Button1 = New System.Windows.Forms.Button() Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter() Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand() Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection() Me.DsStates1 = New dsStates() CType(Me.customersDataSet1, System.ComponentModel.ISupportInitialize).BeginInit() Me.panelVCRControl.SuspendLayout() CType(Me.DsStates1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'labelCity ' Me.labelCity.Location = New System.Drawing.Point(16, 176) Me.labelCity.Name = "labelCity" Me.labelCity.Size = New System.Drawing.Size(64, 16) Me.labelCity.TabIndex = 11 Me.labelCity.Text = "City:" ' 'buttonMoveNext ' Me.buttonMoveNext.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right) Me.buttonMoveNext.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.buttonMoveNext.Location = New System.Drawing.Point(280, 8) Me.buttonMoveNext.Name = "buttonMoveNext" Me.buttonMoveNext.Size = New System.Drawing.Size(32, 32) Me.buttonMoveNext.TabIndex = 2 Me.buttonMoveNext.Text = ">" ' 'customersDataSet1 ' Me.customersDataSet1.DataSetName = "CustomersDataSet" Me.customersDataSet1.Locale = New System.Globalization.CultureInfo("en-US") ' 'labelContact ' Me.labelContact.Location = New System.Drawing.Point(16, 80) Me.labelContact.Name = "labelContact" Me.labelContact.Size = New System.Drawing.Size(64, 16) Me.labelContact.TabIndex = 7 Me.labelContact.Text = "Contact:" ' 'buttonMoveFirst ' Me.buttonMoveFirst.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.buttonMoveFirst.Location = New System.Drawing.Point(8, 8) Me.buttonMoveFirst.Name = "buttonMoveFirst" Me.buttonMoveFirst.Size = New System.Drawing.Size(32, 32) Me.buttonMoveFirst.TabIndex = 0 Me.buttonMoveFirst.Text = "|<" ' 'textBoxID ' Me.textBoxID.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxID.Enabled = False Me.textBoxID.Location = New System.Drawing.Point(88, 16) Me.textBoxID.Name = "textBoxID" Me.textBoxID.ReadOnly = True Me.textBoxID.Size = New System.Drawing.Size(299, 20) Me.textBoxID.TabIndex = 0 Me.textBoxID.Text = "" ' 'textBoxCity ' Me.textBoxCity.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxCity.Location = New System.Drawing.Point(88, 176) Me.textBoxCity.Name = "textBoxCity" Me.textBoxCity.Size = New System.Drawing.Size(216, 20) Me.textBoxCity.TabIndex = 5 Me.textBoxCity.Text = "" ' 'labelContactTitle ' Me.labelContactTitle.Location = New System.Drawing.Point(16, 112) Me.labelContactTitle.Name = "labelContactTitle" Me.labelContactTitle.Size = New System.Drawing.Size(64, 16) Me.labelContactTitle.TabIndex = 8 Me.labelContactTitle.Text = "Title:" ' 'labelCompanyName ' Me.labelCompanyName.Location = New System.Drawing.Point(16, 48) Me.labelCompanyName.Name = "labelCompanyName" Me.labelCompanyName.Size = New System.Drawing.Size(64, 16) Me.labelCompanyName.TabIndex = 6 Me.labelCompanyName.Text = "Company:" ' 'textBoxTitle ' Me.textBoxTitle.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxTitle.Location = New System.Drawing.Point(88, 112) Me.textBoxTitle.Name = "textBoxTitle" Me.textBoxTitle.Size = New System.Drawing.Size(216, 20) Me.textBoxTitle.TabIndex = 3 Me.textBoxTitle.Text = "" ' 'textBoxPosition ' Me.textBoxPosition.Anchor = (System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxPosition.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.textBoxPosition.Enabled = False Me.textBoxPosition.Location = New System.Drawing.Point(88, 14) Me.textBoxPosition.Name = "textBoxPosition" Me.textBoxPosition.ReadOnly = True Me.textBoxPosition.Size = New System.Drawing.Size(184, 20) Me.textBoxPosition.TabIndex = 1 Me.textBoxPosition.Text = "" ' 'labelUSState ' Me.labelUSState.Location = New System.Drawing.Point(16, 208) Me.labelUSState.Name = "labelUSState" Me.labelUSState.Size = New System.Drawing.Size(64, 16) Me.labelUSState.TabIndex = 13 Me.labelUSState.Text = "US State:" ' 'buttonMovePrev ' Me.buttonMovePrev.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.buttonMovePrev.Location = New System.Drawing.Point(48, 8) Me.buttonMovePrev.Name = "buttonMovePrev" Me.buttonMovePrev.Size = New System.Drawing.Size(32, 32) Me.buttonMovePrev.TabIndex = 1 Me.buttonMovePrev.Text = "<" ' 'labelZip ' Me.labelZip.Location = New System.Drawing.Point(16, 240) Me.labelZip.Name = "labelZip" Me.labelZip.Size = New System.Drawing.Size(64, 16) Me.labelZip.TabIndex = 12 Me.labelZip.Text = "Zip:" ' 'textBoxAddress ' Me.textBoxAddress.AcceptsReturn = True Me.textBoxAddress.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxAddress.Location = New System.Drawing.Point(88, 144) Me.textBoxAddress.Name = "textBoxAddress" Me.textBoxAddress.Size = New System.Drawing.Size(360, 20) Me.textBoxAddress.TabIndex = 4 Me.textBoxAddress.Text = "" ' 'textBoxCompany ' Me.textBoxCompany.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxCompany.Location = New System.Drawing.Point(88, 48) Me.textBoxCompany.Name = "textBoxCompany" Me.textBoxCompany.Size = New System.Drawing.Size(296, 20) Me.textBoxCompany.TabIndex = 1 Me.textBoxCompany.Text = "" ' 'panelVCRControl ' Me.panelVCRControl.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.panelVCRControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.panelVCRControl.Controls.AddRange(New System.Windows.Forms.Control() {Me.textBoxPosition, Me.buttonMoveFirst, Me.buttonMovePrev, Me.buttonMoveNext, Me.buttonMoveLast}) Me.panelVCRControl.Location = New System.Drawing.Point(88, 288) Me.panelVCRControl.Name = "panelVCRControl" Me.panelVCRControl.Size = New System.Drawing.Size(360, 48) Me.panelVCRControl.TabIndex = 8 Me.panelVCRControl.Text = "panel1" ' 'buttonMoveLast ' Me.buttonMoveLast.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right) Me.buttonMoveLast.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.buttonMoveLast.Location = New System.Drawing.Point(320, 8) Me.buttonMoveLast.Name = "buttonMoveLast" Me.buttonMoveLast.Size = New System.Drawing.Size(32, 32) Me.buttonMoveLast.TabIndex = 3 Me.buttonMoveLast.Text = ">|" ' 'comboBoxUSState ' Me.comboBoxUSState.Location = New System.Drawing.Point(88, 208) Me.comboBoxUSState.Name = "comboBoxUSState" Me.comboBoxUSState.Size = New System.Drawing.Size(176, 21) Me.comboBoxUSState.TabIndex = 6 ' 'labelAddress ' Me.labelAddress.Location = New System.Drawing.Point(16, 144) Me.labelAddress.Name = "labelAddress" Me.labelAddress.Size = New System.Drawing.Size(64, 16) Me.labelAddress.TabIndex = 9 Me.labelAddress.Text = "Address:" ' 'labelID ' Me.labelID.Location = New System.Drawing.Point(16, 16) Me.labelID.Name = "labelID" Me.labelID.Size = New System.Drawing.Size(64, 16) Me.labelID.TabIndex = 5 Me.labelID.Text = "ID:" ' 'textBoxContact ' Me.textBoxContact.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.textBoxContact.Location = New System.Drawing.Point(88, 80) Me.textBoxContact.Name = "textBoxContact" Me.textBoxContact.Size = New System.Drawing.Size(339, 20) Me.textBoxContact.TabIndex = 2 Me.textBoxContact.Text = "" ' 'textBoxZip ' Me.textBoxZip.Location = New System.Drawing.Point(88, 240) Me.textBoxZip.Name = "textBoxZip" Me.textBoxZip.Size = New System.Drawing.Size(112, 20) Me.textBoxZip.TabIndex = 7 Me.textBoxZip.Text = "" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(276, 208) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(176, 23) Me.Button1.TabIndex = 14 Me.Button1.Text = "Show Values" ' 'SqlDataAdapter1 ' Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1 Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "States", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("StateCode", "StateCode"), New System.Data.Common.DataColumnMapping("StateName", "StateName")})}) ' 'SqlSelectCommand1 ' Me.SqlSelectCommand1.CommandText = "SELECT StateCode, StateName FROM States" Me.SqlSelectCommand1.Connection = Me.SqlConnection1 ' 'SqlConnection1 ' Me.SqlConnection1.ConnectionString = "data source=OSPREY;initial catalog=Northwind;persist security info=False;user id=" & _ "sa;workstation id=OSPREY;packet size=4096" ' 'DsStates1 ' Me.DsStates1.DataSetName = "dsStates" Me.DsStates1.Locale = New System.Globalization.CultureInfo("en-US") Me.DsStates1.Namespace = "http://www.tempuri.org/dsStates.xsd" ' 'ComboBoxBinding ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(464, 357) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.textBoxZip, Me.comboBoxUSState, Me.textBoxCity, Me.labelUSState, Me.labelZip, Me.labelCity, Me.panelVCRControl, Me.textBoxCompany, Me.labelCompanyName, Me.textBoxAddress, Me.textBoxTitle, Me.textBoxContact, Me.textBoxID, Me.labelAddress, Me.labelContactTitle, Me.labelContact, Me.labelID}) Me.Name = "ComboBoxBinding" Me.Text = "Customer Details" CType(Me.customersDataSet1, System.ComponentModel.ISupportInitialize).EndInit() Me.panelVCRControl.ResumeLayout(False) CType(Me.DsStates1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'If Me.comboBoxUSState.Text <> "" Then MessageBox.Show("SelectedValue: " & Me.comboBoxUSState.SelectedValue.ToString & _ " Text: " & Me.comboBoxUSState.Text.ToString & " SelectedIndex: " & Me.comboBoxUSState.SelectedIndex.ToString) 'End If End Sub Private Sub comboBoxUSState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboBoxUSState.SelectedIndexChanged 'If Me.comboBoxUSState.Text <> "" Then ' MessageBox.Show(Me.comboBoxUSState.SelectedValue.ToString & " : " & Me.comboBoxUSState.Text.ToString) 'End If End Sub End Class End Namespace
Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.
For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
- On the Project menu, click Add Class, click VB Class, and then click Open.
In Design view, name the class as dsStates by replacing the autogenerated code with the following code example:
Option Strict Off Option Explicit On Imports System Imports System.Data Imports System.Runtime.Serialization Imports System.Xml <Serializable(), _ System.ComponentModel.DesignerCategoryAttribute("code"), _ System.Diagnostics.DebuggerStepThrough(), _ System.ComponentModel.ToolboxItem(true)> _ Public Class dsStates Inherits DataSet Private tableStates As StatesDataTable Public Sub New() MyBase.New Me.InitClass Dim schemaChangedHandler As System.ComponentModel.CollectionChangeEventHandler = AddressOf Me.SchemaChanged AddHandler Me.Tables.CollectionChanged, schemaChangedHandler AddHandler Me.Relations.CollectionChanged, schemaChangedHandler End Sub Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) MyBase.New Dim strSchema As String = CType(info.GetValue("XmlSchema", GetType(System.String)),String) If (Not (strSchema) Is Nothing) Then Dim ds As DataSet = New DataSet ds.ReadXmlSchema(New XmlTextReader(New System.IO.StringReader(strSchema))) If (Not (ds.Tables("States")) Is Nothing) Then Me.Tables.Add(New StatesDataTable(ds.Tables("States"))) End If Me.DataSetName = ds.DataSetName Me.Prefix = ds.Prefix Me.Namespace = ds.Namespace Me.Locale = ds.Locale Me.CaseSensitive = ds.CaseSensitive Me.EnforceConstraints = ds.EnforceConstraints Me.Merge(ds, false, System.Data.MissingSchemaAction.Add) Me.InitVars Else Me.InitClass End If Me.GetSerializationData(info, context) Dim schemaChangedHandler As System.ComponentModel.CollectionChangeEventHandler = AddressOf Me.SchemaChanged AddHandler Me.Tables.CollectionChanged, schemaChangedHandler AddHandler Me.Relations.CollectionChanged, schemaChangedHandler End Sub <System.ComponentModel.Browsable(false), _ System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _ Public ReadOnly Property States As StatesDataTable Get Return Me.tableStates End Get End Property Public Overrides Function Clone() As DataSet Dim cln As dsStates = CType(MyBase.Clone,dsStates) cln.InitVars Return cln End Function Protected Overrides Function ShouldSerializeTables() As Boolean Return false End Function Protected Overrides Function ShouldSerializeRelations() As Boolean Return false End Function Protected Overrides Sub ReadXmlSerializable(ByVal reader As XmlReader) Me.Reset Dim ds As DataSet = New DataSet ds.ReadXml(reader) If (Not (ds.Tables("States")) Is Nothing) Then Me.Tables.Add(New StatesDataTable(ds.Tables("States"))) End If Me.DataSetName = ds.DataSetName Me.Prefix = ds.Prefix Me.Namespace = ds.Namespace Me.Locale = ds.Locale Me.CaseSensitive = ds.CaseSensitive Me.EnforceConstraints = ds.EnforceConstraints Me.Merge(ds, false, System.Data.MissingSchemaAction.Add) Me.InitVars End Sub Protected Overrides Function GetSchemaSerializable() As System.Xml.Schema.XmlSchema Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream Me.WriteXmlSchema(New XmlTextWriter(stream, Nothing)) stream.Position = 0 Return System.Xml.Schema.XmlSchema.Read(New XmlTextReader(stream), Nothing) End Function Friend Sub InitVars() Me.tableStates = CType(Me.Tables("States"),StatesDataTable) If (Not (Me.tableStates) Is Nothing) Then Me.tableStates.InitVars End If End Sub Private Sub InitClass() Me.DataSetName = "dsStates" Me.Prefix = "" Me.Namespace = "http://www.tempuri.org/dsStates.xsd" Me.Locale = New System.Globalization.CultureInfo("en-US") Me.CaseSensitive = false Me.EnforceConstraints = true Me.tableStates = New StatesDataTable Me.Tables.Add(Me.tableStates) End Sub Private Function ShouldSerializeStates() As Boolean Return false End Function Private Sub SchemaChanged(ByVal sender As Object, ByVal e As System.ComponentModel.CollectionChangeEventArgs) If (e.Action = System.ComponentModel.CollectionChangeAction.Remove) Then Me.InitVars End If End Sub Public Delegate Sub StatesRowChangeEventHandler(ByVal sender As Object, ByVal e As StatesRowChangeEvent) <System.Diagnostics.DebuggerStepThrough()> _ Public Class StatesDataTable Inherits DataTable Implements System.Collections.IEnumerable Private columnStateCode As DataColumn Private columnStateName As DataColumn Friend Sub New() MyBase.New("States") Me.InitClass End Sub Friend Sub New(ByVal table As DataTable) MyBase.New(table.TableName) If (table.CaseSensitive <> table.DataSet.CaseSensitive) Then Me.CaseSensitive = table.CaseSensitive End If If (table.Locale.ToString <> table.DataSet.Locale.ToString) Then Me.Locale = table.Locale End If If (table.Namespace <> table.DataSet.Namespace) Then Me.Namespace = table.Namespace End If Me.Prefix = table.Prefix Me.MinimumCapacity = table.MinimumCapacity Me.DisplayExpression = table.DisplayExpression End Sub <System.ComponentModel.Browsable(false)> _ Public ReadOnly Property Count As Integer Get Return Me.Rows.Count End Get End Property Friend ReadOnly Property StateCodeColumn As DataColumn Get Return Me.columnStateCode End Get End Property Friend ReadOnly Property StateNameColumn As DataColumn Get Return Me.columnStateName End Get End Property Public Default ReadOnly Property Item(ByVal index As Integer) As StatesRow Get Return CType(Me.Rows(index),StatesRow) End Get End Property Public Event StatesRowChanged As StatesRowChangeEventHandler Public Event StatesRowChanging As StatesRowChangeEventHandler Public Event StatesRowDeleted As StatesRowChangeEventHandler Public Event StatesRowDeleting As StatesRowChangeEventHandler Public Overloads Sub AddStatesRow(ByVal row As StatesRow) Me.Rows.Add(row) End Sub Public Overloads Function AddStatesRow(ByVal StateCode As String, ByVal StateName As String) As StatesRow Dim rowStatesRow As StatesRow = CType(Me.NewRow,StatesRow) rowStatesRow.ItemArray = New Object() {StateCode, StateName} Me.Rows.Add(rowStatesRow) Return rowStatesRow End Function Public Function FindByStateCode(ByVal StateCode As String) As StatesRow Return CType(Me.Rows.Find(New Object() {StateCode}),StatesRow) End Function Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator Return Me.Rows.GetEnumerator End Function Public Overrides Function Clone() As DataTable Dim cln As StatesDataTable = CType(MyBase.Clone,StatesDataTable) cln.InitVars Return cln End Function Protected Overrides Function CreateInstance() As DataTable Return New StatesDataTable End Function Friend Sub InitVars() Me.columnStateCode = Me.Columns("StateCode") Me.columnStateName = Me.Columns("StateName") End Sub Private Sub InitClass() Me.columnStateCode = New DataColumn("StateCode", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnStateCode) Me.columnStateName = New DataColumn("StateName", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnStateName) Me.Constraints.Add(New UniqueConstraint("Constraint1", New DataColumn() {Me.columnStateCode}, true)) Me.columnStateCode.AllowDBNull = false Me.columnStateCode.Unique = true Me.columnStateName.AllowDBNull = false End Sub Public Function NewStatesRow() As StatesRow Return CType(Me.NewRow,StatesRow) End Function Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow Return New StatesRow(builder) End Function Protected Overrides Function GetRowType() As System.Type Return GetType(StatesRow) End Function Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs) MyBase.OnRowChanged(e) If (Not (Me.StatesRowChangedEvent) Is Nothing) Then RaiseEvent StatesRowChanged(Me, New StatesRowChangeEvent(CType(e.Row,StatesRow), e.Action)) End If End Sub Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs) MyBase.OnRowChanging(e) If (Not (Me.StatesRowChangingEvent) Is Nothing) Then RaiseEvent StatesRowChanging(Me, New StatesRowChangeEvent(CType(e.Row,StatesRow), e.Action)) End If End Sub Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs) MyBase.OnRowDeleted(e) If (Not (Me.StatesRowDeletedEvent) Is Nothing) Then RaiseEvent StatesRowDeleted(Me, New StatesRowChangeEvent(CType(e.Row,StatesRow), e.Action)) End If End Sub Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs) MyBase.OnRowDeleting(e) If (Not (Me.StatesRowDeletingEvent) Is Nothing) Then RaiseEvent StatesRowDeleting(Me, New StatesRowChangeEvent(CType(e.Row,StatesRow), e.Action)) End If End Sub Public Sub RemoveStatesRow(ByVal row As StatesRow) Me.Rows.Remove(row) End Sub End Class <System.Diagnostics.DebuggerStepThrough()> _ Public Class StatesRow Inherits DataRow Private tableStates As StatesDataTable Friend Sub New(ByVal rb As DataRowBuilder) MyBase.New(rb) Me.tableStates = CType(Me.Table,StatesDataTable) End Sub Public Property StateCode As String Get Return CType(Me(Me.tableStates.StateCodeColumn),String) End Get Set Me(Me.tableStates.StateCodeColumn) = value End Set End Property Public Property StateName As String Get Return CType(Me(Me.tableStates.StateNameColumn),String) End Get Set Me(Me.tableStates.StateNameColumn) = value End Set End Property End Class <System.Diagnostics.DebuggerStepThrough()> _ Public Class StatesRowChangeEvent Inherits EventArgs Private eventRow As StatesRow Private eventAction As DataRowAction Public Sub New(ByVal row As StatesRow, ByVal action As DataRowAction) MyBase.New Me.eventRow = row Me.eventAction = action End Sub Public ReadOnly Property Row As StatesRow Get Return Me.eventRow End Get End Property Public ReadOnly Property Action As DataRowAction Get Return Me.eventAction End Get End Property End Class End Class
- On the Project menu, click Add Class, click VB Class, and then click Open.
In Design view, name the class as CustomerDataSet by replacing the autogenerated code with the following code example:
Option Strict Off Option Explicit On Imports System Imports System.Data Imports System.Runtime.Serialization Imports System.Xml Namespace Microsoft.Samples.WinForms.VB.ComboBoxBinding.Data <Serializable(), _ System.ComponentModel.DesignerCategoryAttribute("code"), _ System.Diagnostics.DebuggerStepThrough(), _ System.ComponentModel.ToolboxItem(true)> _ Public Class CustomersDataSet Inherits DataSet Private tableCustomers As CustomersDataTable Public Sub New() MyBase.New Me.InitClass Dim schemaChangedHandler As System.ComponentModel.CollectionChangeEventHandler = AddressOf Me.SchemaChanged AddHandler Me.Tables.CollectionChanged, schemaChangedHandler AddHandler Me.Relations.CollectionChanged, schemaChangedHandler End Sub Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) MyBase.New Dim strSchema As String = CType(info.GetValue("XmlSchema", GetType(System.String)),String) If (Not (strSchema) Is Nothing) Then Dim ds As DataSet = New DataSet ds.ReadXmlSchema(New XmlTextReader(New System.IO.StringReader(strSchema))) If (Not (ds.Tables("Customers")) Is Nothing) Then Me.Tables.Add(New CustomersDataTable(ds.Tables("Customers"))) End If Me.DataSetName = ds.DataSetName Me.Prefix = ds.Prefix Me.Namespace = ds.Namespace Me.Locale = ds.Locale Me.CaseSensitive = ds.CaseSensitive Me.EnforceConstraints = ds.EnforceConstraints Me.Merge(ds, false, System.Data.MissingSchemaAction.Add) Me.InitVars Else Me.InitClass End If Me.GetSerializationData(info, context) Dim schemaChangedHandler As System.ComponentModel.CollectionChangeEventHandler = AddressOf Me.SchemaChanged AddHandler Me.Tables.CollectionChanged, schemaChangedHandler AddHandler Me.Relations.CollectionChanged, schemaChangedHandler End Sub <System.ComponentModel.Browsable(false), _ System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _ Public ReadOnly Property Customers As CustomersDataTable Get Return Me.tableCustomers End Get End Property Public Overrides Function Clone() As DataSet Dim cln As CustomersDataSet = CType(MyBase.Clone,CustomersDataSet) cln.InitVars Return cln End Function Protected Overrides Function ShouldSerializeTables() As Boolean Return false End Function Protected Overrides Function ShouldSerializeRelations() As Boolean Return false End Function Protected Overrides Sub ReadXmlSerializable(ByVal reader As XmlReader) Me.Reset Dim ds As DataSet = New DataSet ds.ReadXml(reader) If (Not (ds.Tables("Customers")) Is Nothing) Then Me.Tables.Add(New CustomersDataTable(ds.Tables("Customers"))) End If Me.DataSetName = ds.DataSetName Me.Prefix = ds.Prefix Me.Namespace = ds.Namespace Me.Locale = ds.Locale Me.CaseSensitive = ds.CaseSensitive Me.EnforceConstraints = ds.EnforceConstraints Me.Merge(ds, false, System.Data.MissingSchemaAction.Add) Me.InitVars End Sub Protected Overrides Function GetSchemaSerializable() As System.Xml.Schema.XmlSchema Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream Me.WriteXmlSchema(New XmlTextWriter(stream, Nothing)) stream.Position = 0 Return System.Xml.Schema.XmlSchema.Read(New XmlTextReader(stream), Nothing) End Function Friend Sub InitVars() Me.tableCustomers = CType(Me.Tables("Customers"),CustomersDataTable) If (Not (Me.tableCustomers) Is Nothing) Then Me.tableCustomers.InitVars End If End Sub Private Sub InitClass() Me.DataSetName = "CustomersDataSet" Me.Prefix = "" Me.Namespace = "" Me.Locale = New System.Globalization.CultureInfo("en-US") Me.CaseSensitive = false Me.EnforceConstraints = true Me.tableCustomers = New CustomersDataTable Me.Tables.Add(Me.tableCustomers) End Sub Private Function ShouldSerializeCustomers() As Boolean Return false End Function Private Sub SchemaChanged(ByVal sender As Object, ByVal e As System.ComponentModel.CollectionChangeEventArgs) If (e.Action = System.ComponentModel.CollectionChangeAction.Remove) Then Me.InitVars End If End Sub Public Delegate Sub CustomersRowChangeEventHandler(ByVal sender As Object, ByVal e As CustomersRowChangeEvent) <System.Diagnostics.DebuggerStepThrough()> _ Public Class CustomersDataTable Inherits DataTable Implements System.Collections.IEnumerable Private columnCustomerID As DataColumn Private columnCompanyName As DataColumn Private columnContactName As DataColumn Private columnContactTitle As DataColumn Private columnAddress As DataColumn Private columnCity As DataColumn Private column_Region As DataColumn Private columnPostalCode As DataColumn Private columnCountry As DataColumn Private columnPhone As DataColumn Private columnFax As DataColumn Friend Sub New() MyBase.New("Customers") Me.InitClass End Sub Friend Sub New(ByVal table As DataTable) MyBase.New(table.TableName) If (table.CaseSensitive <> table.DataSet.CaseSensitive) Then Me.CaseSensitive = table.CaseSensitive End If If (table.Locale.ToString <> table.DataSet.Locale.ToString) Then Me.Locale = table.Locale End If If (table.Namespace <> table.DataSet.Namespace) Then Me.Namespace = table.Namespace End If Me.Prefix = table.Prefix Me.MinimumCapacity = table.MinimumCapacity Me.DisplayExpression = table.DisplayExpression End Sub <System.ComponentModel.Browsable(false)> _ Public ReadOnly Property Count As Integer Get Return Me.Rows.Count End Get End Property Friend ReadOnly Property CustomerIDColumn As DataColumn Get Return Me.columnCustomerID End Get End Property Friend ReadOnly Property CompanyNameColumn As DataColumn Get Return Me.columnCompanyName End Get End Property Friend ReadOnly Property ContactNameColumn As DataColumn Get Return Me.columnContactName End Get End Property Friend ReadOnly Property ContactTitleColumn As DataColumn Get Return Me.columnContactTitle End Get End Property Friend ReadOnly Property AddressColumn As DataColumn Get Return Me.columnAddress End Get End Property Friend ReadOnly Property CityColumn As DataColumn Get Return Me.columnCity End Get End Property Friend ReadOnly Property _RegionColumn As DataColumn Get Return Me.column_Region End Get End Property Friend ReadOnly Property PostalCodeColumn As DataColumn Get Return Me.columnPostalCode End Get End Property Friend ReadOnly Property CountryColumn As DataColumn Get Return Me.columnCountry End Get End Property Friend ReadOnly Property PhoneColumn As DataColumn Get Return Me.columnPhone End Get End Property Friend ReadOnly Property FaxColumn As DataColumn Get Return Me.columnFax End Get End Property Public Default ReadOnly Property Item(ByVal index As Integer) As CustomersRow Get Return CType(Me.Rows(index),CustomersRow) End Get End Property Public Event CustomersRowChanged As CustomersRowChangeEventHandler Public Event CustomersRowChanging As CustomersRowChangeEventHandler Public Event CustomersRowDeleted As CustomersRowChangeEventHandler Public Event CustomersRowDeleting As CustomersRowChangeEventHandler Public Overloads Sub AddCustomersRow(ByVal row As CustomersRow) Me.Rows.Add(row) End Sub Public Overloads Function AddCustomersRow(ByVal CustomerID As String, ByVal CompanyName As String, ByVal ContactName As String, ByVal ContactTitle As String, ByVal Address As String, ByVal City As String, ByVal _Region As String, ByVal PostalCode As String, ByVal Country As String, ByVal Phone As String, ByVal Fax As String) As CustomersRow Dim rowCustomersRow As CustomersRow = CType(Me.NewRow,CustomersRow) rowCustomersRow.ItemArray = New Object() {CustomerID, CompanyName, ContactName, ContactTitle, Address, City, _Region, PostalCode, Country, Phone, Fax} Me.Rows.Add(rowCustomersRow) Return rowCustomersRow End Function Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator Return Me.Rows.GetEnumerator End Function Public Overrides Function Clone() As DataTable Dim cln As CustomersDataTable = CType(MyBase.Clone,CustomersDataTable) cln.InitVars Return cln End Function Protected Overrides Function CreateInstance() As DataTable Return New CustomersDataTable End Function Friend Sub InitVars() Me.columnCustomerID = Me.Columns("CustomerID") Me.columnCompanyName = Me.Columns("CompanyName") Me.columnContactName = Me.Columns("ContactName") Me.columnContactTitle = Me.Columns("ContactTitle") Me.columnAddress = Me.Columns("Address") Me.columnCity = Me.Columns("City") Me.column_Region = Me.Columns("Region") Me.columnPostalCode = Me.Columns("PostalCode") Me.columnCountry = Me.Columns("Country") Me.columnPhone = Me.Columns("Phone") Me.columnFax = Me.Columns("Fax") End Sub Private Sub InitClass() Me.columnCustomerID = New DataColumn("CustomerID", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCustomerID) Me.columnCompanyName = New DataColumn("CompanyName", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCompanyName) Me.columnContactName = New DataColumn("ContactName", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnContactName) Me.columnContactTitle = New DataColumn("ContactTitle", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnContactTitle) Me.columnAddress = New DataColumn("Address", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnAddress) Me.columnCity = New DataColumn("City", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCity) Me.column_Region = New DataColumn("Region", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.column_Region) Me.columnPostalCode = New DataColumn("PostalCode", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnPostalCode) Me.columnCountry = New DataColumn("Country", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCountry) Me.columnPhone = New DataColumn("Phone", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnPhone) Me.columnFax = New DataColumn("Fax", GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnFax) Me.columnCustomerID.AllowDBNull = false Me.columnCompanyName.AllowDBNull = false End Sub Public Function NewCustomersRow() As CustomersRow Return CType(Me.NewRow,CustomersRow) End Function Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow Return New CustomersRow(builder) End Function Protected Overrides Function GetRowType() As System.Type Return GetType(CustomersRow) End Function Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs) MyBase.OnRowChanged(e) If (Not (Me.CustomersRowChangedEvent) Is Nothing) Then RaiseEvent CustomersRowChanged(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action)) End If End Sub Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs) MyBase.OnRowChanging(e) If (Not (Me.CustomersRowChangingEvent) Is Nothing) Then RaiseEvent CustomersRowChanging(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action)) End If End Sub Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs) MyBase.OnRowDeleted(e) If (Not (Me.CustomersRowDeletedEvent) Is Nothing) Then RaiseEvent CustomersRowDeleted(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action)) End If End Sub Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs) MyBase.OnRowDeleting(e) If (Not (Me.CustomersRowDeletingEvent) Is Nothing) Then RaiseEvent CustomersRowDeleting(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action)) End If End Sub Public Sub RemoveCustomersRow(ByVal row As CustomersRow) Me.Rows.Remove(row) End Sub End Class <System.Diagnostics.DebuggerStepThrough()> _ Public Class CustomersRow Inherits DataRow Private tableCustomers As CustomersDataTable Friend Sub New(ByVal rb As DataRowBuilder) MyBase.New(rb) Me.tableCustomers = CType(Me.Table,CustomersDataTable) End Sub Public Property CustomerID As String Get Return CType(Me(Me.tableCustomers.CustomerIDColumn),String) End Get Set Me(Me.tableCustomers.CustomerIDColumn) = value End Set End Property Public Property CompanyName As String Get Return CType(Me(Me.tableCustomers.CompanyNameColumn),String) End Get Set Me(Me.tableCustomers.CompanyNameColumn) = value End Set End Property Public Property ContactName As String Get Try Return CType(Me(Me.tableCustomers.ContactNameColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.ContactNameColumn) = value End Set End Property Public Property ContactTitle As String Get Try Return CType(Me(Me.tableCustomers.ContactTitleColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.ContactTitleColumn) = value End Set End Property Public Property Address As String Get Try Return CType(Me(Me.tableCustomers.AddressColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.AddressColumn) = value End Set End Property Public Property City As String Get Try Return CType(Me(Me.tableCustomers.CityColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.CityColumn) = value End Set End Property Public Property _Region As String Get Try Return CType(Me(Me.tableCustomers._RegionColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers._RegionColumn) = value End Set End Property Public Property PostalCode As String Get Try Return CType(Me(Me.tableCustomers.PostalCodeColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.PostalCodeColumn) = value End Set End Property Public Property Country As String Get Try Return CType(Me(Me.tableCustomers.CountryColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.CountryColumn) = value End Set End Property Public Property Phone As String Get Try Return CType(Me(Me.tableCustomers.PhoneColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.PhoneColumn) = value End Set End Property Public Property Fax As String Get Try Return CType(Me(Me.tableCustomers.FaxColumn),String) Catch e As InvalidCastException Throw New StrongTypingException("Cannot get value because it is DBNull.", e) End Try End Get Set Me(Me.tableCustomers.FaxColumn) = value End Set End Property Public Function IsContactNameNull() As Boolean Return Me.IsNull(Me.tableCustomers.ContactNameColumn) End Function Public Sub SetContactNameNull() Me(Me.tableCustomers.ContactNameColumn) = System.Convert.DBNull End Sub Public Function IsContactTitleNull() As Boolean Return Me.IsNull(Me.tableCustomers.ContactTitleColumn) End Function Public Sub SetContactTitleNull() Me(Me.tableCustomers.ContactTitleColumn) = System.Convert.DBNull End Sub Public Function IsAddressNull() As Boolean Return Me.IsNull(Me.tableCustomers.AddressColumn) End Function Public Sub SetAddressNull() Me(Me.tableCustomers.AddressColumn) = System.Convert.DBNull End Sub Public Function IsCityNull() As Boolean Return Me.IsNull(Me.tableCustomers.CityColumn) End Function Public Sub SetCityNull() Me(Me.tableCustomers.CityColumn) = System.Convert.DBNull End Sub Public Function Is_RegionNull() As Boolean Return Me.IsNull(Me.tableCustomers._RegionColumn) End Function Public Sub Set_RegionNull() Me(Me.tableCustomers._RegionColumn) = System.Convert.DBNull End Sub Public Function IsPostalCodeNull() As Boolean Return Me.IsNull(Me.tableCustomers.PostalCodeColumn) End Function Public Sub SetPostalCodeNull() Me(Me.tableCustomers.PostalCodeColumn) = System.Convert.DBNull End Sub Public Function IsCountryNull() As Boolean Return Me.IsNull(Me.tableCustomers.CountryColumn) End Function Public Sub SetCountryNull() Me(Me.tableCustomers.CountryColumn) = System.Convert.DBNull End Sub Public Function IsPhoneNull() As Boolean Return Me.IsNull(Me.tableCustomers.PhoneColumn) End Function Public Sub SetPhoneNull() Me(Me.tableCustomers.PhoneColumn) = System.Convert.DBNull End Sub Public Function IsFaxNull() As Boolean Return Me.IsNull(Me.tableCustomers.FaxColumn) End Function Public Sub SetFaxNull() Me(Me.tableCustomers.FaxColumn) = System.Convert.DBNull End Sub End Class <System.Diagnostics.DebuggerStepThrough()> _ Public Class CustomersRowChangeEvent Inherits EventArgs Private eventRow As CustomersRow Private eventAction As DataRowAction Public Sub New(ByVal row As CustomersRow, ByVal action As DataRowAction) MyBase.New Me.eventRow = row Me.eventAction = action End Sub Public ReadOnly Property Row As CustomersRow Get Return Me.eventRow End Get End Property Public ReadOnly Property Action As DataRowAction Get Return Me.eventAction End Get End Property End Class End Class End Namespace
- On the Project menu, click ComboBoxBinding properties, and then click Sub Main in the Start up Object list.
Note In Visual Studio .NET 2002, right click ComboBoxBinding in Solution Explorer, click properties, choose Sub Main in Startup Object, and then click OK.
- On the Debug menu, click Start.
- Move through the Previous and Next records to see the behavior that is mentioned in the "Symptoms" section.
Keywords: kbvs2005swept kbvs2005applies kbprb KB894501