我要疯了。试着自学vb.net。我来自vba背景,花了几个小时试图从一个数字表上的T-SQL查询创建一个两列列表框。
我可以让它列出一列,但仅此而已。
我想没有人能告诉我我错在哪里?我用的是最好的方法吗?
MsgBox("hello")
LblTest.Text = "Hello World"
LblTest.ForeColor = Color.Red
Dim connectionString As String = "Data Source=CHRISTINES-DESKSQL2008EXPRESS;
InitialCatalog=Trading;Persist Security Info=True;User ID=sa;Password=########"
Dim connection As New SqlConnection(connectionString)
Dim selectQuery As String = "SELECT Breakeven.Spend, Breakeven.Gain FROM levels"
Dim command As New SqlCommand(selectQuery, connection)
connection.Open()
ListBox1.DisplayMember = "Spend"
ListBox1.DisplayMember = "Cost"
Dim reader As SqlDataReader = command.ExecuteReader()
Me.ListBox1.FormattingEnabled = True
Me.ListBox1.ScrollAlwaysVisible = True
Me.ListBox1.MultiColumn = True
While reader.Read()
Dim item1 As Decimal = reader.GetDecimal(0)
Dim item2 As Decimal = reader.GetDecimal(1)
ListBox1.Items.Add(New MyItem(item1, item2))
Debug.Print(item1 & " - " & item2)
End While
reader.Close()
connection.Close()
In form:
ListBox1.BackColor = SystemColors.Menu
ListBox1.ColumnWidth = 80
ListBox1.FormattingEnabled = True
ListBox1.ItemHeight = 15
ListBox1.Location = New Point(18, 59)
ListBox1.MultiColumn = True
ListBox1.Name = "ListBox1"
ListBox1.Size = New Size(310, 334)
ListBox1.TabIndex = 2
我试了所有我能找到的方法——甚至是聊天来寻求答案,我都解决不了。
像这个问题,我建议使用listview。
如何在Visual Basic中创建多列列表框?