LISTVIEW的VEW属性设置为DETAILS
与VB6相比,VB.NET操作LISTVIEW要麻烦些,不清晰些。
窗体装载时需要初始化LISTVIEW
Private Sub FrmMergeInWeightBaseWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LVData.Columns.Add("序号")
LVData.Columns.Add("发货方")
LVData.Columns.Add("收货方")
LVData.Columns.Add("车号")
LVData.Columns.Add("品名")
LVData.Columns.Add("等级")
LVData.Columns.Add("是否散装")
LVData.Columns.Add("水分")
LVData.Columns.Add("杂质")
LVData.Columns.Add("其他")
LVData.Columns.Add("仓号")
LVData.Columns.Add("发货人")
LVData.Columns.Add("收货人")
LVData.Columns.Add("毛重")
LVData.Columns.Add("毛重时间")
LVData.Columns.Add("毛检员")
LVData.Columns.Add("毛重锁")
LVData.Columns.Add("皮重")
LVData.Columns.Add("皮重时间")
LVData.Columns.Add("皮检员")
LVData.Columns.Add("皮重锁")
LVData.Columns.Add("净重")
LVData.Columns.Add("麻袋件数")
LVData.Columns.Add("麻袋重")
LVData.Columns.Add("编织袋数")
LVData.Columns.Add("编织袋重")
LVData.Columns.Add("包装扣重")
LVData.Columns.Add("水杂扣量")
LVData.Columns.Add("扣重锁")
LVData.Columns.Add("扣包装后净重")
LVData.Columns.Add("原发净重")
LVData.Columns.Add("增减量")
LVData.Columns.Add("打印锁")
LVData.Columns.Add("毛重操作")
LVData.Columns.Add("皮重操作")
LVData.Columns.Add("省")
LVData.Columns.Add("市")
LVData.Columns.Add("县")
LVData.Columns.Add("公司")
LVData.Columns.Add("是否上传")
Call CommFillDictContentByTbName(SendCompany, "tbMergeIndictSendCompany")
Call CommFillDictContentByTbName(ReceiveCompany, "tbMergeIndictReceiveCompany")
Call CommFillDictContentByTbName(CarNum, "tbMergeIndictcarnum")
Call CommFillDictContentByTbName(Breed, "tbMergeIndictbreed")
Call CommFillDictContentByTbName(SendPeople, "tbMergeIndictSendpeople")
Call CommFillDictContentByTbName(ReceivePeople, "tbMergeIndictReceivepeople")
Call CommFillDictContentByTbName(StoreNum, "tbMergeIndictstorenum")
'这里使用列宽度
Call GetColumnWidth("tbColumnWidth_MergeInBaseWindow", LVData.Columns.Count, LVData)
End Sub
查询按钮如下
Private Sub BtnQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuery.Click
MergeInAmount.Text = "查询结果总数: "
LVData.Items.Clear()
Dim cn As New SqlConnection("Server=" & g_DatabaseServerIp & ";Initial Catalog=" & g_DatabaseName & ";UID=" & g_DatabaseUser & ";Pwd=" & g_DatabaseUserPassword)
cn.Open()
Dim Cmd As New SqlCommand()
Cmd.Connection = cn
Cmd.CommandText = "prMergeInWindowsDetailQuery " & Chr(39) & STime.Text & Chr(39) & " , " & Chr(39) & ETime.Text & Chr(39) & " , " & Chr(39) & SendCompany.Text & Chr(39) & " , " & Chr(39) & ReceiveCompany.Text & Chr(39) & " , " & Chr(39) & Breed.Text & Chr(39) & " , " & Chr(39) & CarNum.Text & Chr(39) & " , " & Chr(39) & SendPeople.Text & Chr(39) & " , " & Chr(39) & ReceivePeople.Text & Chr(39) & " , " & Chr(39) & IsDisperse.Text & Chr(39) & " , " & Chr(39) & StoreNum.Text & Chr(39)
Dim dr As SqlDataReader
dr = Cmd.ExecuteReader()
If dr.HasRows() = True Then
Do While dr.Read() = True
Dim tmpItem As ListViewItem
tmpItem = LVData.Items.Add(IIf(IsDBNull(dr.Item("id")) = True, "", dr.Item("id")))
tmpItem.StateImageIndex = MergeInIcoStatu(dr.Item("TotalWeightLock"), dr.Item("CarWeightLock"), dr.Item("PrintLock"))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("SendCompany")) = True, "", dr.Item("SendCompany")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("ReceiveCompany")) = True, "", dr.Item("ReceiveCompany")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("CarNum")) = True, "", dr.Item("CarNum")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Breed")) = True, "", dr.Item("Breed")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Grade")) = True, "", dr.Item("Grade")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("IsDisperse")) = True, "", dr.Item("IsDisperse")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Water")) = True, "", dr.Item("Water")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Impurity")) = True, "", dr.Item("Impurity")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Other")) = True, "", dr.Item("Other")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("SendPeople")) = True, "", dr.Item("SendPeople")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("ReceivePeople")) = True, "", dr.Item("ReceivePeople")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("StoreNum")) = True, "", dr.Item("StoreNum")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("TotalWeight")) = True, "", Format(dr.Item("TotalWeight"), "0,0")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("TotalWeightTime")) = True, "", dr.Item("TotalWeightTime")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("TotalWeighter")) = True, "", dr.Item("TotalWeighter")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("TotalWeightLock")) = True, "", dr.Item("TotalWeightLock")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("CarWeight")) = True, "", dr.Item("CarWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("CarWeightTime")) = True, "", dr.Item("CarWeightTime")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("CarWeighter")) = True, "", dr.Item("CarWeighter")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("CarWeightLock")) = True, "", dr.Item("CarWeightLock")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("PureWeight")) = True, "", dr.Item("PureWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("HarlAmount")) = True, "", dr.Item("HarlAmount")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("HarlWeight")) = True, "", dr.Item("HarlWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("MeshAmount")) = True, "", dr.Item("MeshAmount")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("MeshWeight")) = True, "", dr.Item("MeshWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("PackSubWeight")) = True, "", dr.Item("PackSubWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("NowSubWeight")) = True, "", dr.Item("NowSubWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("SubWeightLock")) = True, "", dr.Item("SubWeightLock")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("PureWeightAfterSubPack")) = True, "", dr.Item("PureWeightAfterSubPack")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("OriPureWeight")) = True, "", dr.Item("OriPureWeight")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("AddSubAmount")) = True, "", dr.Item("AddSubAmount")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("PrintLock")) = True, "", dr.Item("PrintLock")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("TotalWeightHandle")) = True, "", dr.Item("TotalWeightHandle")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("CarWeightHandle")) = True, "", dr.Item("CarWeightHandle")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Province")) = True, "", dr.Item("Province")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("City")) = True, "", dr.Item("City")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("County")) = True, "", dr.Item("County")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("Company")) = True, "", dr.Item("Company")))
tmpItem.SubItems.Add(IIf(IsDBNull(dr.Item("IsUp")) = True, "", dr.Item("IsUp")))
Loop
End If
dr.Close()
Cmd.Dispose()
cn.Dispose()
MergeInAmount.Text = "查询结果总数: " & LVData.Items.Count
End Sub