第二个Listview不显示任何信息(但具有滚动条) [英] Second Listview doesn't show any information (But it has a scrollbar)
本文介绍了第二个Listview不显示任何信息(但具有滚动条)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我遇到了一个选项卡式Windows窗体的问题,该窗体应该在两个选项卡下显示不同的信息.该代码很好地填充了第一个列表视图,但是第二个仅显示了一个滚动条.到目前为止,这是我的代码.谢谢任何帮助这个新角的人.
我确实收到此错误:Microsoft.VisualBasic.dll中出现了类型为"System.ArgumentException"的第一次机会异常
Hi Everyone,
I am having trouble with a tabbed windows form that is supposed to display different information under two tabs. The code populates the first listview fine but the second one only shows a scroll bar. Here is my code so far. Thank you anyone who helps this greenhorn.
I do get this error: A first chance exception of type ''System.ArgumentException'' occurred in Microsoft.VisualBasic.dll
Dim sCompanyID As String
Dim sNameID As String
Private ColumnsSet As Boolean = False
Private Const ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=S:\Tracker\Tracker_Tables.mdb"
Private cn As OleDbConnection = New OleDbConnection(ConnString)
Private Sub frmCompanyProfile_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CompanyTypesTableAdapter.Fill(Me.Tracker_TablesDataSet.CompanyTypes)
Call FillForm()
Call lvEmployeesFill()
Call lvSalesFill()
End Sub
Private Sub lvEmployeesFill()
Dim cmd As OleDbCommand
cmd = New OleDbCommand("SELECT [NameID], [First], [Last] FROM [CustomerNames] WHERE [CompanyID]=" & sCompanyID, cn)
Filllistview(lvEmployees, cmd)
End Sub
Private Sub lvSalesFill()
Dim cmd As OleDbCommand
cmd = New OleDbCommand("SELECT [CompanyID] FROM [Sales] WHERE [CompanyID]=" & sCompanyID, cn)
Filllistview(LVSales, cmd)
End Sub
Private Sub Filllistview(ByVal objListView As ListView, ByRef cmd As OleDbCommand)
cn.Open()
Dim RowList As ArrayList = New ArrayList()
Dim reader As OleDbDataReader = cmd.ExecuteReader()
Do While Reader.Read()
Dim Values(Reader.FieldCount) As Object
Reader.GetValues(Values)
RowList.Add(Values)
Loop
If Not ColumnsSet Then
Dim schema As DataTable = Reader.GetSchemaTable()
SetColumnHeaders(objListView, schema)
End If
Reader.Close()
cn.Close()
PopulateList(objListView, RowList)
End Sub
Private Sub SetColumnHeaders(ByVal objListView As ListView, ByVal schema As DataTable)
Dim row As DataRow
objListView.View = View.Details
For Each row In schema.Rows
objListView.Columns.Add(row("ColumnName"), 100, HorizontalAlignment.Left)
Next
ColumnsSet = True
End Sub
Private Sub PopulateList(ByVal objListView As ListView, ByVal RowList As ArrayList)
objListView.Items.Clear()
Dim row As Object()
For Each row In RowList
Dim OrderDetails(row.Length) As String
'Dim col As Object
Dim ColIdx As Integer
For ColIdx = 0 To row.Length - 1
OrderDetails(ColIdx) = Convert.ToString(row(ColIdx))
Next
Dim NewItem As ListViewItem = New ListViewItem(OrderDetails)
objListView.Items.Add(NewItem)
Next
End Sub
推荐答案
在"SetColumnHeaders(..)"中,为列表视图创建列.
这仅适用于第一个列表视图,因为您设置了ColumnsSet
填充第一个变量时将class变量设置为true.然后,当
填充第二个变量,此变量已设置为true,您
不要在第二个列表视图中再次执行此操作.
因此,您的listview可能有数据(您看到滚动条),但是没有列.
那该例外呢?它在哪里抛出,什么为空?
Hi,
in "SetColumnHeaders(..)" you create the columns for your listviews.
That only works for the first listview, as you set the ColumnsSet
class variable to true while filling the first one. Then, when
filling the second one, this variable is already set to true and you
dont do it again for the second listview.
So, your listview may have data (you see scrollbars), but it has no columns.
And what about that exception? Where is it thrown, what is null?
非常感谢!!!我的学习还在继续.
〜杰克
Thank you so much!!! My learning continues.
~Jack
这篇关于第二个Listview不显示任何信息(但具有滚动条)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文