原思路:全局代码:
Public ComboxItemStr As String = "" '定义字符串,等待事件中传递参数
‘其实我这里是想把一组数据库行 赋值给combox,现在用的字符串传递,方法很笨
Public Class FormData
Inherits System.Windows.Forms.Form
Private Sub FormData_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ComboBoxData = New System.Windows.Forms.ComboBox
Me.ComboBoxData.FormattingEnabled = True
Me.ComboBoxData.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Dim Values() As String
Values = ComboxItemStr.split(",") ‘这里解析字符串,并用items.add赋值,能不能这里直接指定数据源,指定显示值 ???????
For Index As Integer = 0 To Values.Length - 1
Me.ComboBoxData.Items.Add(Values(Index))
Next
Me.ComboBoxData.Location = New System.Drawing.Point(85, 27)
Me.ComboBoxData.Name = "ComboBoxData"
Me.ComboBoxData.Size = New System.Drawing.Size(156, 20)
Me.ComboBoxData.TabIndex = 0
BeforeOpenProject事件代码
Dim con As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\之数据源切换\DBconfig.mdb;Persist Security Info=False")
Dim cmd As New System.Data.OleDb.OleDbCommand("Select * FROM 设置", con)
Dim DataReader As System.Data.OleDb.OleDbDataReader '定义DataReader对象
con.Open()
DataReader = cmd.ExecuteReader '执行SQL语句,返回给DataReader对象
While DataReader.Read
ComboxItemStr = ComboxItemStr & "," & DataReader("用户可选数据源")
End While
con.Close()
ComboxItemStr = ComboxItemStr.trim(",") ' 这是是用来赋值的
'先读取外部数据库配置文件
Dim frm As New FormData
frm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
frm.TopMost = True '或 e.HideSplashForm = True
frm.ShowDialog() '模式打开
'请问在以上代码或全局代码中能不能给frm里的comobox用数据源赋值,当然,用数组也行?
If ButtonNo Then
e.Cancel = True
End If
If ButtonYes Then
'这里返回的是用户选择的项目,这里是字符串,能不能返回数据行.?
msgbox(DataStr)
End If
现在的想法
能不能在 事件 里直接 将 数据行 指定给ComboBoxData,并指定显示列
,当用户选择不同项目时,以方便直接调用 选定记录行的列数据
[此贴子已经被作者于2013-12-31 9:22:10编辑过]