VB.Net by API/System.Windows.Forms/ComboBox
Содержание
ComboBox.DataSource
<source lang="vbnet"> Imports System Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Collections Imports System.Windows.Forms Imports System.Resources Public Class MainClass
Shared Sub Main() Dim form1 As Form = New Form1() Application.Run(form1) End Sub
End Class
Public Class Form1
"Form level variables Private strConnectionString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=Employee.mdb;" Private objConnection As OleDbConnection Private objCommand As OleDbCommand Private objDataAdapter As OleDbDataAdapter Private objDataTable As DataTable Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load "Initialize the Connection object objConnection = New OleDbConnection(strConnectionString) "Initialize the Command object objCommand = New OleDbCommand("SELECT ID, FirstName " & _ "FROM Employee", objConnection) "Initialize the DataAdapter object and set the SelectCommand property objDataAdapter = New OleDbDataAdapter objDataAdapter.SelectCommand = objCommand "Initialize the DataTable object objDataTable = New DataTable "Populate the DataTable objDataAdapter.Fill(objDataTable) "Bind the DataTable to the ComboBox ComboBox1.DataSource = objDataTable ComboBox1.DisplayMember = "FirstName" ComboBox1.ValueMember = "ID" "Clean up objDataAdapter.Dispose() objDataAdapter = Nothing objCommand.Dispose() objCommand = Nothing objConnection.Dispose() objConnection = Nothing End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1
Inherits System.Windows.Forms.Form "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.Label1 = New System.Windows.Forms.Label Me.SuspendLayout() " "ComboBox1 " Me.ruboBox1.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList Me.ruboBox1.FormattingEnabled = True Me.ruboBox1.Location = New System.Drawing.Point(76, 13) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(205, 21) Me.ruboBox1.TabIndex = 3 " "Label1 " Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(13, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(41, 13) Me.Label1.TabIndex = 2 Me.Label1.Text = "Name" " "Form1 " Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(292, 76) Me.Controls.Add(Me.ruboBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
</source>
ComboBox.DisplayMember
<source lang="vbnet"> Imports System Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Collections Imports System.Windows.Forms Imports System.Resources Public Class MainClass
Shared Sub Main() Dim form1 As Form = New Form1() Application.Run(form1) End Sub
End Class
Public Class Form1
"Form level variables Private strConnectionString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=Employee.mdb;" Private objConnection As OleDbConnection Private objCommand As OleDbCommand Private objDataAdapter As OleDbDataAdapter Private objDataTable As DataTable Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load "Initialize the Connection object objConnection = New OleDbConnection(strConnectionString) "Initialize the Command object objCommand = New OleDbCommand("SELECT ID, FirstName " & _ "FROM Employee", objConnection) "Initialize the DataAdapter object and set the SelectCommand property objDataAdapter = New OleDbDataAdapter objDataAdapter.SelectCommand = objCommand "Initialize the DataTable object objDataTable = New DataTable "Populate the DataTable objDataAdapter.Fill(objDataTable) "Bind the DataTable to the ComboBox ComboBox1.DataSource = objDataTable ComboBox1.DisplayMember = "FirstName" ComboBox1.ValueMember = "ID" "Clean up objDataAdapter.Dispose() objDataAdapter = Nothing objCommand.Dispose() objCommand = Nothing objConnection.Dispose() objConnection = Nothing End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1
Inherits System.Windows.Forms.Form "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.Label1 = New System.Windows.Forms.Label Me.SuspendLayout() " "ComboBox1 " Me.ruboBox1.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList Me.ruboBox1.FormattingEnabled = True Me.ruboBox1.Location = New System.Drawing.Point(76, 13) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(205, 21) Me.ruboBox1.TabIndex = 3 " "Label1 " Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(13, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(41, 13) Me.Label1.TabIndex = 2 Me.Label1.Text = "Name" " "Form1 " Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(292, 76) Me.Controls.Add(Me.ruboBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
</source>
ComboBox.DrawItem
<source lang="vbnet">
Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D <Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1
Inherits System.Windows.Forms.Form "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.XButton = New System.Windows.Forms.Button Me.ColorList = New System.Windows.Forms.ruboBox Me.SuspendLayout() " "XButton " Me.XButton.Location = New System.Drawing.Point(112, 24) Me.XButton.Name = "XButton" Me.XButton.Size = New System.Drawing.Size(75, 23) Me.XButton.TabIndex = 0 Me.XButton.Text = "Button1" Me.XButton.UseVisualStyleBackColor = True " "ColorList " Me.ColorList.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed Me.ColorList.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList Me.ColorList.FormattingEnabled = True Me.ColorList.Location = New System.Drawing.Point(88, 64) Me.ColorList.Name = "ColorList" Me.ColorList.Size = New System.Drawing.Size(121, 21) Me.ColorList.TabIndex = 1 " "Form1 " Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(292, 221) Me.Controls.Add(Me.ColorList) Me.Controls.Add(Me.XButton) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.MaximizeBox = False Me.Name = "Form1" Me.Text = "Control Drawing" Me.ResumeLayout(False) End Sub Friend WithEvents XButton As System.Windows.Forms.Button Friend WithEvents ColorList As System.Windows.Forms.ruboBox
End Class Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ColorList.Items.Add("Red") ColorList.Items.Add("Orange") ColorList.Items.Add("Yellow") ColorList.Items.Add("Green") ColorList.Items.Add("Blue") ColorList.Items.Add("Indigo") ColorList.Items.Add("Violet") End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawEllipse(Pens.Black, 10, 10, Me.ClientRectangle.Width - 20, _ Me.ClientRectangle.Height - 20) End Sub Private Sub XButton_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles XButton.Paint Dim usePen As Pen e.Graphics.Clear(SystemColors.Control) usePen = New Pen(SystemColors.ControlText, 3) e.Graphics.DrawRectangle(usePen, XButton.ClientRectangle) usePen.Dispose() End Sub Private Sub ColorList_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ColorList.DrawItem Dim useBrush As Brush If (e.Index = -1) Then Return e.DrawBackground() useBrush = New SolidBrush(Color.FromName(CStr(ColorList.Items(e.Index)))) e.Graphics.FillRectangle(useBrush, _ e.Bounds.Left + 2, e.Bounds.Top + 2, _ e.Bounds.Width - 4, e.Bounds.Height - 4) useBrush.Dispose() e.Graphics.DrawRectangle(Pens.Black, _ e.Bounds.Left + 2, e.Bounds.Top + 2, _ e.Bounds.Width - 4, e.Bounds.Height - 4) e.DrawFocusRectangle() End Sub Private Sub XButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XButton.Click MsgBox("Button clicked.") End Sub
End Class public class ComboBoxCellRenderer
public Shared Sub Main Application.Run(New Form1) End Sub
End class
</source>
ComboBox.Items.Add
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class ComboBoxSelectionEventAddValue
public Shared Sub Main Application.Run(New Form1) End Sub
End class Public Class Form1
Inherits System.Windows.Forms.Form
- Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() "This call is required by the Windows Form Designer. InitializeComponent() "Add any initialization after the InitializeComponent() call End Sub "Form overrides dispose to clean up the component list. 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 "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.TextBox1 = New System.Windows.Forms.TextBox Me.SuspendLayout() " "ComboBox1 " Me.ruboBox1.Location = New System.Drawing.Point(72, 72) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(121, 21) Me.ruboBox1.TabIndex = 0 Me.ruboBox1.Text = "ComboBox1" " "TextBox1 " Me.TextBox1.Location = New System.Drawing.Point(16, 168) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(256, 20) Me.TextBox1.TabIndex = 2 Me.TextBox1.Text = "" " "Form1 " Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.ruboBox1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub
- End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To 10 ComboBox1.Items.Add("Item " + i.ToString()) Next ComboBox1.Text = "Choose one..." End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim intSelectedIndex As Integer intSelectedIndex = ComboBox1.SelectedIndex Dim objSelectedItem As Object objSelectedItem = ComboBox1.SelectedItem TextBox1.Text = "Item"s index: " & intSelectedIndex & _ ". Item"s text: " & objSelectedItem.ToString() End Sub
End Class
</source>
ComboBox.SelectedIndexChanged
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class ComboBoxSelectionEventAddValue
public Shared Sub Main Application.Run(New Form1) End Sub
End class Public Class Form1
Inherits System.Windows.Forms.Form
- Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() "This call is required by the Windows Form Designer. InitializeComponent() "Add any initialization after the InitializeComponent() call End Sub "Form overrides dispose to clean up the component list. 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 "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.TextBox1 = New System.Windows.Forms.TextBox Me.SuspendLayout() " "ComboBox1 " Me.ruboBox1.Location = New System.Drawing.Point(72, 72) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(121, 21) Me.ruboBox1.TabIndex = 0 Me.ruboBox1.Text = "ComboBox1" " "TextBox1 " Me.TextBox1.Location = New System.Drawing.Point(16, 168) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(256, 20) Me.TextBox1.TabIndex = 2 Me.TextBox1.Text = "" " "Form1 " Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.ruboBox1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub
- End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To 10 ComboBox1.Items.Add("Item " + i.ToString()) Next ComboBox1.Text = "Choose one..." End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim intSelectedIndex As Integer intSelectedIndex = ComboBox1.SelectedIndex Dim objSelectedItem As Object objSelectedItem = ComboBox1.SelectedItem TextBox1.Text = "Item"s index: " & intSelectedIndex & _ ". Item"s text: " & objSelectedItem.ToString() End Sub
End Class
</source>
ComboBox.SelectedItem
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class ComboBoxSelectionEventAddValue
public Shared Sub Main Application.Run(New Form1) End Sub
End class Public Class Form1
Inherits System.Windows.Forms.Form
- Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() "This call is required by the Windows Form Designer. InitializeComponent() "Add any initialization after the InitializeComponent() call End Sub "Form overrides dispose to clean up the component list. 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 "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.TextBox1 = New System.Windows.Forms.TextBox Me.SuspendLayout() " "ComboBox1 " Me.ruboBox1.Location = New System.Drawing.Point(72, 72) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(121, 21) Me.ruboBox1.TabIndex = 0 Me.ruboBox1.Text = "ComboBox1" " "TextBox1 " Me.TextBox1.Location = New System.Drawing.Point(16, 168) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(256, 20) Me.TextBox1.TabIndex = 2 Me.TextBox1.Text = "" " "Form1 " Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.ruboBox1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub
- End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To 10 ComboBox1.Items.Add("Item " + i.ToString()) Next ComboBox1.Text = "Choose one..." End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim intSelectedIndex As Integer intSelectedIndex = ComboBox1.SelectedIndex Dim objSelectedItem As Object objSelectedItem = ComboBox1.SelectedItem TextBox1.Text = "Item"s index: " & intSelectedIndex & _ ". Item"s text: " & objSelectedItem.ToString() End Sub
End Class
</source>
ComboBox.Text
<source lang="vbnet"> Imports System.Windows.Forms public class GetComboBoxText
public Shared Sub Main Application.Run(New Form1) End Sub
End class Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click Dim Language As String Language = ComboBox1.Text If Language = "Visual Basic" Then MsgBox("We have a winner!") Else MsgBox(Language & " is not a bad language.") End If End Sub
End Class Partial Public Class Form1
Inherits System.Windows.Forms.Form <System.Diagnostics.DebuggerNonUserCode()> _ Public Sub New() MyBase.New() "This call is required by the Windows Form Designer. InitializeComponent() End Sub "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.Button1 = New System.Windows.Forms.Button Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.SuspendLayout() " "Label1 " Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(13, 22) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(160, 14) Me.Label1.TabIndex = 0 Me.Label1.Text = "What"s your favorite language?" " "Button1 " Me.Button1.Location = New System.Drawing.Point(13, 70) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(267, 23) Me.Button1.TabIndex = 2 Me.Button1.Text = "Evaluate my choice" " "ComboBox1 " Me.ruboBox1.FormattingEnabled = True Me.ruboBox1.Items.AddRange(New Object() {"C++", "C#", "Java", "Visual Basic", "Cobol"}) Me.ruboBox1.Location = New System.Drawing.Point(13, 43) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(267, 21) Me.ruboBox1.TabIndex = 1 " "Form1 " Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 117) Me.Controls.Add(Me.ruboBox1) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox
End Class
</source>
ComboBox.ValueMember
<source lang="vbnet"> Imports System Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Collections Imports System.Windows.Forms Imports System.Resources Public Class MainClass
Shared Sub Main() Dim form1 As Form = New Form1() Application.Run(form1) End Sub
End Class
Public Class Form1
"Form level variables Private strConnectionString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=Employee.mdb;" Private objConnection As OleDbConnection Private objCommand As OleDbCommand Private objDataAdapter As OleDbDataAdapter Private objDataTable As DataTable Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load "Initialize the Connection object objConnection = New OleDbConnection(strConnectionString) "Initialize the Command object objCommand = New OleDbCommand("SELECT ID, FirstName " & _ "FROM Employee", objConnection) "Initialize the DataAdapter object and set the SelectCommand property objDataAdapter = New OleDbDataAdapter objDataAdapter.SelectCommand = objCommand "Initialize the DataTable object objDataTable = New DataTable "Populate the DataTable objDataAdapter.Fill(objDataTable) "Bind the DataTable to the ComboBox ComboBox1.DataSource = objDataTable ComboBox1.DisplayMember = "FirstName" ComboBox1.ValueMember = "ID" "Clean up objDataAdapter.Dispose() objDataAdapter = Nothing objCommand.Dispose() objCommand = Nothing objConnection.Dispose() objConnection = Nothing End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1
Inherits System.Windows.Forms.Form "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ruboBox1 = New System.Windows.Forms.ruboBox Me.Label1 = New System.Windows.Forms.Label Me.SuspendLayout() " "ComboBox1 " Me.ruboBox1.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList Me.ruboBox1.FormattingEnabled = True Me.ruboBox1.Location = New System.Drawing.Point(76, 13) Me.ruboBox1.Name = "ComboBox1" Me.ruboBox1.Size = New System.Drawing.Size(205, 21) Me.ruboBox1.TabIndex = 3 " "Label1 " Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(13, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(41, 13) Me.Label1.TabIndex = 2 Me.Label1.Text = "Name" " "Form1 " Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(292, 76) Me.Controls.Add(Me.ruboBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
</source>