In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What are the relevant operation methods and functions of VB.NET LISTVIEW? I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problems. Through this article, I hope you can solve this problem.
In the VB.NET development framework, there are also many controls for developers to use, convenient to achieve a variety of graphical interface and program functional requirements. For example, VB.NET LISTVIEW, which we introduce here, is a development control that can help us to sort.
Controls:
TEXTBOX: 1 Name:txtJobNo
BUTTON: 2 Name:btnFilter,btnShowAll
LISTVIEW: 1 Name:lstvwJobNo Columns:JobNo,ContainerID,CartonID,PO,Style,Color,Size,ShipMent,Factory Sorting:none
VB.NET LISTVIEW writes the source code:
Imports System.Data.SqlClient
Dim con As New SqlConnection
Dim varSQL As String
Dim r As Integer
Dim conString As String =
"data source=127.0.0.1;initial
Catalog=mydb; uid=sa;password=123 "
'define the default sort variable
Dim mySort As String = "ASC"
'The VB.NET LISTVIEW defines the default field variable
Dim myField As String
= "JOB.JOBNO"
'filter the records for the specified condition
Private Sub btnFilter_Click (ByVal
Sender As System.Object, ByVal e
As System.EventArgs) Handles
BtnFilter.Click
Try
Dim fJobNo As String = ""
FJobNo = txtJobNo.Text.Trim ()
R = List_dgJobNo (fJobNo)
Catch ex As Exception
MessageBox.Show (ex.ToString)
Finally
If con.State = ConnectionState.
Open Then
Con.Close ()
End If
End Try
End Sub
'VB.NET LISTVIEW displays all records
Private Sub btnShowAll_Click
(ByVal sender As System.Object
ByVal e As System.EventArgs)
Handles btnShowAll.Click
List_dgJobNo ("")
End Sub
Function function: write the read data into the table of lstvwJovNo
'function name: List_dgJobNo, call format: List_dgJobNo ("10022"), List_dgJobNo ("")
'parameter: fJobNo. The work number to be queried is JOBNO. If it is empty, all the
'edited by: SD
'Day period: 2005-9-23
'Reprint, please keep this information.
Private Function List_dgJobNo (ByVal
FJobNo As String) As Integer
Try
Cursor.Current = Cursors.WaitCursor
LstvwJobNo.Items.Clear ()
Con = New SqlConnection (conString)
Dim cmd As SqlCommand
Dim rd As SqlDataReader
If fJobNo.Length > 0 Then
VarSQL = "SELECT JOB.JOBNO,CONTAINERNO
CARTONFROM,PO,STYLE,COLOR,CARTONSIZE
SHIPMENT,FACTORY FROM JOB,JOB_LINE
WHERE JOB.JOBNO=JOB_LINE.JOBNO AND JOB.
JOBNO LIKE'% "& fJobNo &"%'"
Else
VarSQL = "SELECT JOB.JOBNO,CONTAINERNO
CARTONFROM,PO,STYLE,COLOR,CARTONSIZE
SHIPMENT,FACTORY FROM JOB,JOB_LINE
WHERE JOB.JOBNO=JOB_LINE.JOBNO "
End If
VarSQLvarSQL = varSQL & "ORDER BY"
& myField & "& mySort &";
Cmd = New SqlCommand (varSQL, con)
Rd = cmd.ExecuteReader
Dim lsv As ListViewItem
While rd.Read
Lsv = New ListViewItem (rd ("JOBNO") .ToString)
'lsv.Checked = True
Lsv.SubItems.Add (rd ("ContainerNo") .ToString)
Lsv.SubItems.Add (rd ("CartonFrom") .ToString)
Lsv.SubItems.Add (rd ("PO") .ToString)
Lsv.SubItems.Add (rd ("Style") .ToString)
Lsv.SubItems.Add (rd ("Color") .ToString)
Lsv.SubItems.Add (rd ("CartonSize") .ToString)
Lsv.SubItems.Add (rd ("ShipMent") .ToString)
Lsv.SubItems.Add (rd ("Factory") .ToString)
LstvwJobNo.Items.Add (lsv)
End While
Cursor.Current = Cursors.Default
Return List_dgJobNo = 1
Catch ex As Exception
MessageBox.Show (ex.ToString)
Return List_dgJobNo =-1
Finally
If con.State = ConnectionState.Open Then
Con.Close ()
End If
End Try
End Function
'VB.NET LISTVIEW gets the sorted field and displays the sort tag
Private Sub lstvwJobNo_ColumnClick
(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs)
Handles lstvwJobNo.ColumnClick
Select Case e.Column.ToString
Case 0
MyField = "JOB.JOBNO"
Case 1
MyField = "CONTAINERNO"
Case 2
MyField = "CARTONFROM"
Case 3
MyField = "PO"
Case 4
MyField = "STYLE"
Case 5
MyField = "COLOR"
Case 6
MyField = "CARTONSIZE"
Case 7
MyField = "SHIPMENT"
Case 8
MyField = "FACTORY"
End Select
Dim i As Integer
For I = 0 To 8
LstvwJobNo.Columns (I) .Text =
LstvwJobNo.Columns (I) .Text.Replace
("▼", ""). Replace ("▲", "")
Next
If mySort = "ASC" Then
LstvwJobNo.Columns (e.Column.ToString)
.Text = lstvwJobNo.Columns (e.Column.
ToString). Text & "▼"
MySort = "DESC"
Else
MySort = "ASC"
LstvwJobNo.Columns (e.Column.ToString).
Text = lstvwJobNo.Columns (e.Column.
ToString). Text & "▲"
End If
Dim fJobNo As String = ""
FJobNo = txtJobNo.Text.Trim ()
R = List_dgJobNo (fJobNo)
LstvwJobNo.Refresh ()
End Sub
After reading the above, have you mastered the relevant operation methods and functions of VB.NET LISTVIEW? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.