Microsoft KB Archive/894501

= The sequence of next and previous values may not correctly appear in a ComboBox control that is bound to a table field in Visual Studio .NET or in Visual Studio 2005 =

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.



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, 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(&quot;server=(local);Trusted_Connection=yes;database=northwind&quot;) Dim cmd As SqlDataAdapter = New SqlDataAdapter(&quot;Select * from Customers &quot;, con) cmd.Fill(customersDataSet1, &quot;Customers&quot;) Dim cmd1 As SqlDataAdapter = New SqlDataAdapter(&quot;Select StateCode, StateName from States&quot;, con) cmd1.Fill(DsStates1, &quot;MyStates&quot;)

' Set up the Combobox control bindings. 'comboBoxUSState.DataSource = USStates         ' Populate the list comboBoxUSState.DataSource = DsStates1.Tables(&quot;MyStates&quot;) comboBoxUSState.DisplayMember = &quot;StateName&quot;  ' Define the field that will be displayed. comboBoxUSState.ValueMember = &quot;StateCode&quot;    ' 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(&quot;SelectedValue&quot;, customersDataSet1, &quot;Customers.Region&quot;)

' Set up the rest of the form bindings. textBoxID.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.CustomerID&quot;) textBoxCity.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.City&quot;) textBoxTitle.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.ContactTitle&quot;) textBoxAddress.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.Address&quot;) textBoxCompany.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.CompanyName&quot;) textBoxContact.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.ContactName&quot;) textBoxZip.DataBindings.Add(&quot;Text&quot;, customersDataSet1, &quot;Customers.PostalCode&quot;)

' Handle position changing events for the DATA VCR panel. AddHandler Me.BindingContext(customersDataSet1, &quot;Customers&quot;).PositionChanged, AddressOf customers_PositionChanged

' Set up the initial text for the DATA VCR panel. textBoxPosition.Text = &quot;Record &quot; + (Me.BindingContext(customersDataSet1, &quot;Customers&quot;).Position + 1).ToString + &quot; of &quot; + 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, &quot;Customers&quot;).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, &quot;Customers&quot;).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, &quot;Customers&quot;).Position < customersDataSet1.Customers.Count - 1 Then ' Unselect the previously selected comboBoxUSState value. Me.BindingContext(customersDataSet1, &quot;Customers&quot;).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, &quot;Customers&quot;).Position > 0 Then ' Unselect the previously selected comboBoxUSState value. Me.BindingContext(customersDataSet1, &quot;Customers&quot;).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 = &quot;Record &quot; + (Me.BindingContext(customersDataSet1, &quot;Customers&quot;).Position + 1).ToString + &quot; of &quot; + 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


 * 1) Region &quot; Windows Form Designer generated code &quot;

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 = &quot;labelCity&quot; Me.labelCity.Size = New System.Drawing.Size(64, 16) Me.labelCity.TabIndex = 11 Me.labelCity.Text = &quot;City:&quot; '           '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 = &quot;buttonMoveNext&quot; Me.buttonMoveNext.Size = New System.Drawing.Size(32, 32) Me.buttonMoveNext.TabIndex = 2 Me.buttonMoveNext.Text = &quot;>&quot; '           'customersDataSet1 '           Me.customersDataSet1.DataSetName = &quot;CustomersDataSet&quot; Me.customersDataSet1.Locale = New System.Globalization.CultureInfo(&quot;en-US&quot;) '           'labelContact '           Me.labelContact.Location = New System.Drawing.Point(16, 80) Me.labelContact.Name = &quot;labelContact&quot; Me.labelContact.Size = New System.Drawing.Size(64, 16) Me.labelContact.TabIndex = 7 Me.labelContact.Text = &quot;Contact:&quot; '           'buttonMoveFirst '           Me.buttonMoveFirst.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.buttonMoveFirst.Location = New System.Drawing.Point(8, 8) Me.buttonMoveFirst.Name = &quot;buttonMoveFirst&quot; Me.buttonMoveFirst.Size = New System.Drawing.Size(32, 32) Me.buttonMoveFirst.TabIndex = 0 Me.buttonMoveFirst.Text = &quot;|<&quot; '           '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 = &quot;textBoxID&quot; Me.textBoxID.ReadOnly = True Me.textBoxID.Size = New System.Drawing.Size(299, 20) Me.textBoxID.TabIndex = 0 Me.textBoxID.Text = &quot;&quot; '           '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 = &quot;textBoxCity&quot; Me.textBoxCity.Size = New System.Drawing.Size(216, 20) Me.textBoxCity.TabIndex = 5 Me.textBoxCity.Text = &quot;&quot; '           'labelContactTitle '           Me.labelContactTitle.Location = New System.Drawing.Point(16, 112) Me.labelContactTitle.Name = &quot;labelContactTitle&quot; Me.labelContactTitle.Size = New System.Drawing.Size(64, 16) Me.labelContactTitle.TabIndex = 8 Me.labelContactTitle.Text = &quot;Title:&quot; '           'labelCompanyName '           Me.labelCompanyName.Location = New System.Drawing.Point(16, 48) Me.labelCompanyName.Name = &quot;labelCompanyName&quot; Me.labelCompanyName.Size = New System.Drawing.Size(64, 16) Me.labelCompanyName.TabIndex = 6 Me.labelCompanyName.Text = &quot;Company:&quot; '           '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 = &quot;textBoxTitle&quot; Me.textBoxTitle.Size = New System.Drawing.Size(216, 20) Me.textBoxTitle.TabIndex = 3 Me.textBoxTitle.Text = &quot;&quot; '           '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 = &quot;textBoxPosition&quot; Me.textBoxPosition.ReadOnly = True Me.textBoxPosition.Size = New System.Drawing.Size(184, 20) Me.textBoxPosition.TabIndex = 1 Me.textBoxPosition.Text = &quot;&quot; '           'labelUSState '           Me.labelUSState.Location = New System.Drawing.Point(16, 208) Me.labelUSState.Name = &quot;labelUSState&quot; Me.labelUSState.Size = New System.Drawing.Size(64, 16) Me.labelUSState.TabIndex = 13 Me.labelUSState.Text = &quot;US State:&quot; '           'buttonMovePrev '           Me.buttonMovePrev.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.buttonMovePrev.Location = New System.Drawing.Point(48, 8) Me.buttonMovePrev.Name = &quot;buttonMovePrev&quot; Me.buttonMovePrev.Size = New System.Drawing.Size(32, 32) Me.buttonMovePrev.TabIndex = 1 Me.buttonMovePrev.Text = &quot;<&quot; '           'labelZip '           Me.labelZip.Location = New System.Drawing.Point(16, 240) Me.labelZip.Name = &quot;labelZip&quot; Me.labelZip.Size = New System.Drawing.Size(64, 16) Me.labelZip.TabIndex = 12 Me.labelZip.Text = &quot;Zip:&quot; '           '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 = &quot;textBoxAddress&quot; Me.textBoxAddress.Size = New System.Drawing.Size(360, 20) Me.textBoxAddress.TabIndex = 4 Me.textBoxAddress.Text = &quot;&quot; '           '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 = &quot;textBoxCompany&quot; Me.textBoxCompany.Size = New System.Drawing.Size(296, 20) Me.textBoxCompany.TabIndex = 1 Me.textBoxCompany.Text = &quot;&quot; '           '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 = &quot;panelVCRControl&quot; Me.panelVCRControl.Size = New System.Drawing.Size(360, 48) Me.panelVCRControl.TabIndex = 8 Me.panelVCRControl.Text = &quot;panel1&quot; '           '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 = &quot;buttonMoveLast&quot; Me.buttonMoveLast.Size = New System.Drawing.Size(32, 32) Me.buttonMoveLast.TabIndex = 3 Me.buttonMoveLast.Text = &quot;>|&quot; '           'comboBoxUSState '           Me.comboBoxUSState.Location = New System.Drawing.Point(88, 208) Me.comboBoxUSState.Name = &quot;comboBoxUSState&quot; 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 = &quot;labelAddress&quot; Me.labelAddress.Size = New System.Drawing.Size(64, 16) Me.labelAddress.TabIndex = 9 Me.labelAddress.Text = &quot;Address:&quot; '           'labelID '           Me.labelID.Location = New System.Drawing.Point(16, 16) Me.labelID.Name = &quot;labelID&quot; Me.labelID.Size = New System.Drawing.Size(64, 16) Me.labelID.TabIndex = 5 Me.labelID.Text = &quot;ID:&quot; '           '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 = &quot;textBoxContact&quot; Me.textBoxContact.Size = New System.Drawing.Size(339, 20) Me.textBoxContact.TabIndex = 2 Me.textBoxContact.Text = &quot;&quot; '           'textBoxZip '           Me.textBoxZip.Location = New System.Drawing.Point(88, 240) Me.textBoxZip.Name = &quot;textBoxZip&quot; Me.textBoxZip.Size = New System.Drawing.Size(112, 20) Me.textBoxZip.TabIndex = 7 Me.textBoxZip.Text = &quot;&quot; '           'Button1 '           Me.Button1.Location = New System.Drawing.Point(276, 208) Me.Button1.Name = &quot;Button1&quot; Me.Button1.Size = New System.Drawing.Size(176, 23) Me.Button1.TabIndex = 14 Me.Button1.Text = &quot;Show Values&quot; '           'SqlDataAdapter1 '           Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1 Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping {New System.Data.Common.DataTableMapping(&quot;Table&quot;, &quot;States&quot;, New System.Data.Common.DataColumnMapping {New System.Data.Common.DataColumnMapping(&quot;StateCode&quot;, &quot;StateCode&quot;), New System.Data.Common.DataColumnMapping(&quot;StateName&quot;, &quot;StateName&quot;)})}) '           'SqlSelectCommand1 '           Me.SqlSelectCommand1.CommandText = &quot;SELECT StateCode, StateName FROM States&quot; Me.SqlSelectCommand1.Connection = Me.SqlConnection1 '           'SqlConnection1 '           Me.SqlConnection1.ConnectionString = &quot;data source=OSPREY;initial catalog=Northwind;persist security info=False;user id=&quot; & _ &quot;sa;workstation id=OSPREY;packet size=4096&quot; '           'DsStates1 '           Me.DsStates1.DataSetName = &quot;dsStates&quot; Me.DsStates1.Locale = New System.Globalization.CultureInfo(&quot;en-US&quot;) Me.DsStates1.Namespace = &quot;http://www.tempuri.org/dsStates.xsd&quot; '           '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 = &quot;ComboBoxBinding&quot; Me.Text = &quot;Customer Details&quot; CType(Me.customersDataSet1, System.ComponentModel.ISupportInitialize).EndInit Me.panelVCRControl.ResumeLayout(False) CType(Me.DsStates1, System.ComponentModel.ISupportInitialize).EndInit Me.ResumeLayout(False)

End Sub


 * 1) End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'If Me.comboBoxUSState.Text <> &quot;&quot; Then MessageBox.Show(&quot;SelectedValue: &quot; & Me.comboBoxUSState.SelectedValue.ToString & _               &quot; Text: &quot; & Me.comboBoxUSState.Text.ToString & &quot; SelectedIndex: &quot; & 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 <> &quot;&quot; Then '   MessageBox.Show(Me.comboBoxUSState.SelectedValue.ToString & &quot; : &quot; & 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:

http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx

For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/ms171843.aspx

 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(&quot;code&quot;), _ 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(&quot;XmlSchema&quot;, 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(&quot;States&quot;)) Is Nothing) Then Me.Tables.Add(New StatesDataTable(ds.Tables(&quot;States&quot;))) 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(&quot;States&quot;)) Is Nothing) Then Me.Tables.Add(New StatesDataTable(ds.Tables(&quot;States&quot;))) 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(&quot;States&quot;),StatesDataTable) If (Not (Me.tableStates) Is Nothing) Then Me.tableStates.InitVars End If   End Sub Private Sub InitClass Me.DataSetName = &quot;dsStates&quot; Me.Prefix = &quot;&quot; Me.Namespace = &quot;http://www.tempuri.org/dsStates.xsd&quot; Me.Locale = New System.Globalization.CultureInfo(&quot;en-US&quot;) 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(&quot;States&quot;) 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(&quot;StateCode&quot;) Me.columnStateName = Me.Columns(&quot;StateName&quot;) End Sub Private Sub InitClass Me.columnStateCode = New DataColumn(&quot;StateCode&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnStateCode) Me.columnStateName = New DataColumn(&quot;StateName&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnStateName) Me.Constraints.Add(New UniqueConstraint(&quot;Constraint1&quot;, 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 </li> On the Project menu, click Add Class, click VB Class, and then click Open.</li>  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(&quot;code&quot;), _ 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(&quot;XmlSchema&quot;, 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(&quot;Customers&quot;)) Is Nothing) Then Me.Tables.Add(New CustomersDataTable(ds.Tables(&quot;Customers&quot;))) 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(&quot;Customers&quot;)) Is Nothing) Then Me.Tables.Add(New CustomersDataTable(ds.Tables(&quot;Customers&quot;))) 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(&quot;Customers&quot;),CustomersDataTable) If (Not (Me.tableCustomers) Is Nothing) Then Me.tableCustomers.InitVars End If       End Sub Private Sub InitClass Me.DataSetName = &quot;CustomersDataSet&quot; Me.Prefix = &quot;&quot; Me.Namespace = &quot;&quot; Me.Locale = New System.Globalization.CultureInfo(&quot;en-US&quot;) 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(&quot;Customers&quot;) 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(&quot;CustomerID&quot;) Me.columnCompanyName = Me.Columns(&quot;CompanyName&quot;) Me.columnContactName = Me.Columns(&quot;ContactName&quot;) Me.columnContactTitle = Me.Columns(&quot;ContactTitle&quot;) Me.columnAddress = Me.Columns(&quot;Address&quot;) Me.columnCity = Me.Columns(&quot;City&quot;) Me.column_Region = Me.Columns(&quot;Region&quot;) Me.columnPostalCode = Me.Columns(&quot;PostalCode&quot;) Me.columnCountry = Me.Columns(&quot;Country&quot;) Me.columnPhone = Me.Columns(&quot;Phone&quot;) Me.columnFax = Me.Columns(&quot;Fax&quot;) End Sub Private Sub InitClass Me.columnCustomerID = New DataColumn(&quot;CustomerID&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCustomerID) Me.columnCompanyName = New DataColumn(&quot;CompanyName&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCompanyName) Me.columnContactName = New DataColumn(&quot;ContactName&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnContactName) Me.columnContactTitle = New DataColumn(&quot;ContactTitle&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnContactTitle) Me.columnAddress = New DataColumn(&quot;Address&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnAddress) Me.columnCity = New DataColumn(&quot;City&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCity) Me.column_Region = New DataColumn(&quot;Region&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.column_Region) Me.columnPostalCode = New DataColumn(&quot;PostalCode&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnPostalCode) Me.columnCountry = New DataColumn(&quot;Country&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnCountry) Me.columnPhone = New DataColumn(&quot;Phone&quot;, GetType(System.String), Nothing, System.Data.MappingType.Element) Me.Columns.Add(Me.columnPhone) Me.columnFax = New DataColumn(&quot;Fax&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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(&quot;Cannot get value because it is DBNull.&quot;, 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 </li> 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.

</li> On the Debug menu, click Start.</li> Move through the Previous and Next records to see the behavior that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

Keywords: kbvs2005swept kbvs2005applies kbprb KB894501

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.