Vb. ListView Sort in net

Source: Internet
Author: User
Sort


Control:

Textbox:1 a name:txtjobno.

Button:2 a name:btnfilter,btnshowall.

Listview:1 a name:lstvwjobno columns:jobno,containerid,cartonid,po,style,color,size,shipment,factory Sorting:none


Source:

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 default sort variables
Dim Mysort as String = "ASC"

' Define default field variables
Dim MyField as String = "JOB." Jobno "

Filter records for specified criteria
    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


' Show 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: Writes the read data to the LSTVWJOVNO table
' Function name: list_dgjobno, calling Format: List_dgjobno ("10022"), List_dgjobno ("")
' Parameters: Fjobno, the work number to query Jobno, empty time query all
' Creator: SD
' Date: 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

Varsql = 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


' Get the sorted field and show 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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.