国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

VB.NET中LISTVIEW排序

2024-07-10 13:07:11
字體:
來源:轉載
供稿:網友


控件:

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


源代碼:

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"


'定義默認排序變量
dim mysort as string = "asc"

'定義默認字段變量
dim myfield as string = "job.jobno"

'過濾指定條件的記錄
    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


'顯示所有記錄
private sub btnshowall_click(byval sender as system.object, byval e as system.eventargs) handles btnshowall.click
        list_dgjobno("")
end sub


'函數功能:將讀取出來的數據寫入lstvwjovno的表格中
'函數名稱:list_dgjobno,調用格式:list_dgjobno("10022"),list_dgjobno("")
'參    數:fjobno,要查詢的工作號jobno,為空時則查詢所有的
'編 寫 者:sd
'日    期:2005-9-23
'轉載請保留此信息
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


'獲得排序的字段,并顯示排序標記
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


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 根河市| 五家渠市| 洛南县| 方山县| 尖扎县| 措美县| 隆尧县| 信宜市| 东宁县| 得荣县| 宁安市| 马尔康县| 鄂伦春自治旗| 赞皇县| 鸡泽县| 漳浦县| 德清县| 黄冈市| 井冈山市| 连云港市| 五河县| 五常市| 岐山县| 恩平市| 邹城市| 武宁县| 岳普湖县| 泰来县| 民县| 德昌县| 禄丰县| 永平县| 锡林郭勒盟| 应城市| 盐池县| 自治县| 启东市| 昌平区| 秭归县| 昌黎县| 富锦市|