前端之家收集整理的这篇文章主要介绍了
[VB.NET]vb.net中 listbox 问题,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
vb.net中 list
Box 问题 vb.net中 list
Box控件 数据通过
数据库绑定
显示多条记录 设为多选后 在界面上选择两条以上记录时
后台怎样能够取得所选记录的值 为什么我取得总是system........之类的 __________________________________________________________________________ Me.List
Box1.SelectedItems(0).ToString() Me.List
Box1.SelectedItems(1).ToString() 这样就行了吧? __________________________________________________________________________ Dim i As Integer For i = 0 To List
Box1.SelectedItems.Count - 1 Message
Box.Show(Me.List
Box1.SelectedItems(i).ToString()) Next __________________________________________________________________________ list
Box 绑定
代码 List
Box1.DataSource = Db.OraDataView List
Box1.DisplayMember = “字段名” 取值 For i As Integer = 0 To List
Box1.SelectedItems.Count - 1 Message
Box.Show(Me.List
Box1.SelectedItems(i).ToString()) Next
显示为: System.Data.DataRowView 而不是我
数据库里的值 这是怎么回事啊 __________________________________________________________________________ While Rd.Read() List
Box1.Items.Add(Rd.Item( "a ")) End While 绑定后再测试没有问题! __________________________________________________________________________ Rd 是什么啊 __________________________________________________________________________ Dim Conn As OleDbConnection Dim Cmd As OleDbCommand Dim Rd As OleDbDataReader Dim
sql As String Dim Adpt As OleDbDataAdapter Dim Ds As DataSet Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0 " Dim Database = "Data Source= " & Application.StartupPath() & "/db1.mdb " Conn = New OleDbConnection(Provider & "; " & Database) Conn.Open() ''打开
数据库 sql = "Select * From one " Cmd = New OleDbCommand(
sql,Conn) Rd = Cmd.ExecuteReader() While Rd.Read() List
Box1.Items.Add(Rd.Item( "a ")) End While Rd.Close() Conn.Close() __________________________________________________________________________