同样的做法在VS2003下可以运行,为什么在VS2005下不能运行,请高手指点.(在VB.NET中也有发贴子)
同样的做法在VS2003下可以运行,为什么在VS2005下不能运行,请高手指点
操作步骤:
拖一个ComboBox 到窗体上命名为ComboBoxName
进入代码 导入命名空间
vb.net为: Imports System.Data.SqlClient
c#为:using System.Data.SqlClient;
vb.net2003下的代码为:
' 匯入命名空間
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
' CurrencyManager 物件的類別層級宣告
Dim bmFoxStudio As BindingManagerBase
' 这里是Windows 窗体设计器生成的代码,,就省了。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBoxName.DataSource = CreateDataSource()
ComboBoxName.DisplayMember = "id "
bmFoxStudio = Me.BindingContext(CreateDataSource())
End Sub
Private Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn( "id ", GetType(Int32)))
dt.Columns.Add(New DataColumn( "PkID ", GetType(String)))
For i As Integer = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "破晓之阳 "
dt.Rows.Add(dr)
Next
Dim dv As New DataView(dt)
Return dv
End Function
Private Sub ComboBoxName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxName.SelectedIndexChanged
bmFoxStudio.Position = Me.ComboBoxName.SelectedIndex
End Sub
End Class
vb.net2005 代码:
Imports System.Data.SqlClient
Public Class Form1
Dim bmFoxStudio As BindingManagerBase
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e