找回密码
 加入
搜索
查看: 4016|回复: 10

[GUI管理] 【求助】listview如何实现这样的排序

  [复制链接]
发表于 2011-12-28 14:41:18 | 显示全部楼层 |阅读模式
本帖最后由 yangyunbo 于 2011-12-28 14:42 编辑

具体情况请看图:


下面是小弟的源码,只实现了导入及导出数据,还不能实现排序,故请论坛各位高手帮帮忙。
#include <Array.au3>
#include <ButtonConstants.au3>
#include <Excel.au3>
#Include <GuiEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <ListViewEditEvent.au3> 
#include <WindowsConstants.au3>
;---------------------------------------------
Local $List[2],$Test[2] = ["姓名|总分|A德育素质|德育素质排名|B智育素质|智育素质排名|能力素质|能力素质排名"]
;--------------------------------------------
$Form0 = GUICreate("综合量化分统计", 850, 650,-1, -1)

$Lab01 = GUICtrlCreateLabel("姓名",00,20,60,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input01 = GUICtrlCreateInput("",50,20,100,25);测评成绩输入框
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)

$Lab02 = GUICtrlCreateLabel("德育分",165,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input02 = GUICtrlCreateInput("",245,20,55,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetLimit(-1,4)

$Lab03 = GUICtrlCreateLabel("智育分",310,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input03 = GUICtrlCreateInput("",390,20,55,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetLimit(-1,4)

$Lab04 = GUICtrlCreateLabel("能力分",465,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input04 = GUICtrlCreateInput("",545,20,70,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetLimit(-1,4)

$Lab05 = GUICtrlCreateLabel("总成绩",625,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input05 = GUICtrlCreateInput("",705,20,70,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
_GUICtrlEdit_SetReadOnly($Input05,True)

$tijiao = GUICtrlCreateButton("提交",785,17,60,30)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetState($tijiao,$GUI_DISABLE)
;-------------------------------------------------
$List[0] = GUICtrlCreateListView($Test[0], 5, 50, 840,595) ;列表
GUICtrlSetFont(-1, 12, 800, 0, "微软雅黑")
_GUICtrlListView_SetExtendedListViewStyle($List[0], BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES));添加网格
_GUICtrlListView_SetColumn($List[0], 0, "姓名", 101, 2);设置列属性
_GUICtrlListView_SetColumn($List[0], 1, "总分", 101, 2);
_GUICtrlListView_SetColumn($List[0], 2, "A德育素质", 101, 2)
_GUICtrlListView_SetColumn($List[0], 3, "德育素质排名", 110, 2)
_GUICtrlListView_SetColumn($List[0], 4, "B智育素质", 101, 2)
_GUICtrlListView_SetColumn($List[0], 5, "智育素质排名", 110, 2)
_GUICtrlListView_SetColumn($List[0], 6, "C能力素质", 101, 2)
_GUICtrlListView_SetColumn($List[0], 7, "能力素质排名", 110, 2)
GUICtrlSetColor($List[0], 0x0055ff);设置指定控件的文本颜色
GUICtrlSetResizing($List[0], $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKMENUBAR)
$zhucaidan = GUICtrlCreateContextMenu($List[0])
$shanchu = GUICtrlCreateMenuItem("删除", $zhucaidan)
$daochu = GUICtrlCreateMenuItem("导出", $zhucaidan)
$qingkong = GUICtrlCreateMenuItem("清空", $zhucaidan)
;-----------------------------------
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND");注册一个消息函数
GUISetState(@SW_SHOW)
;---------------------------------------------------------
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
Case $GUI_EVENT_CLOSE
        Exit
;--------------------------
Case $tijiao
        $xingming = GUICtrlRead($Input01)
    $deyu = GUICtrlRead($Input02)
    $zhiyu = GUICtrlRead($Input03)
    $nengli = GUICtrlRead($Input04)
    $zongfen = GUICtrlRead($Input05)
 GUICtrlCreateListViewItem($xingming &"|" &$zongfen &"|" &$deyu &"|" &"" &"|" &$zhiyu &"|" &"" &"|" &$nengli &"|" &"",$List[0])
        GUICtrlSetData($Input01,"")
        GUICtrlSetData($Input02,"")
        GUICtrlSetData($Input03,"")
        GUICtrlSetData($Input04,"")
        GUICtrlSetData($Input05,"")
;----------------------------
Case $shanchu;删除
        $hang = _GUICtrlListView_GetSelectedIndices($List[0]) 
If $hang<>"" Then
         _GUICtrlListView_DeleteItem($List[0],Number($hang))        
 ElseIf $hang="" Then
         MsgBox(16,"提示","没有选择删除的行")
EndIf
;----------------
Case $qingkong;清空
         $neirong = ControlListView("综合量化分统计","",$List[0],"GetItemCount")
If $neirong =0 Then
         MsgBox(16,"错误","列表是空的")
ElseIf MsgBox(33,"提示","确定要清空列表吗?")=1 Then 
        _GUICtrlListView_DeleteAllItems($List[0])
Else
    EndIf
;---------------
Case $daochu;导出
    $biaoge = ControlListView("综合量化分统计","",$List[0],"GetItemCount")
If $biaoge =0 Then
   MsgBox(16,"错误","列表是空的")        
Else
        daochu()
EndIf
;--------------
    EndSwitch
WEnd
;-------------------------------------消息函数:输入框内容导入表格
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local Const $EN_CHANGE = 0x300
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID= BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam 
;------------------------------------------------------------------------------------------
If GUICtrlRead($Input02)=""  Or GUICtrlRead($Input03)="" Or GUICtrlRead($Input04)="" Then
    If BitAND(GUICtrlgetState($tijiao),$GUI_ENABLE) then GUICtrlSetState($tijiao,$GUI_DISABLE)
Else
        If BitAND(GUICtrlgetState($tijiao),$GUI_DISABLE) then GUICtrlSetState($tijiao,$GUI_ENABLE)

EndIf
;-------------
If GUICtrlRead($Input02)<>""  Or GUICtrlRead($Input03)<>"" Or GUICtrlRead($Input04)<>"" Then
    GUICtrlSetData($Input05,GUICtrlRead($Input02)+GUICtrlRead($Input03)+GUICtrlRead($Input04))
Else
         GUICtrlSetData($Input05,"")
 EndIf
;-------------------------------------------------------------------------------------------
        $read1 = GUICtrlRead($Input02)
If String(StringLeft($read1,1))=="0" Or String(StringLeft($read1,1))=="." Then
    GUICtrlSetData($Input02,StringRegExpReplace($read1,'^0+|^\.+',''))
        Else
$write=StringRegExpReplace($read1,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
        if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
GUICtrlSetData($Input02,$write)
        EndIf
If StringLeft($read1,4)>20 Then 
        MsgBox(16,"提示","输入错误,请输入小于或等于20的数")
        GUICtrlSetData($Input02,"")
EndIf
 ;----------------------------------限制德育素质输入框的首字母不能为“0”、“.”及不能大于20
    $read2 = GUICtrlRead($Input03)
If String(StringLeft($read2,1))=="0" Or String(StringLeft($read2,1))=="." Then
    GUICtrlSetData($Input03,StringRegExpReplace($read2,'^0+|^\.+',''))
        Else
$write=StringRegExpReplace($read2,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
        if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
GUICtrlSetData($Input03,$write)
        EndIf
If StringLeft($read2,4)> 50 Then 
        MsgBox(16,"提示","输入错误,请输入小于或等于50的数")
        GUICtrlSetData($Input03,"")
EndIf
;----------------------------------限制智育素质输入框的首位不能为“0”、“.”及不能大于50
    $read3 = GUICtrlRead($Input04)
If String(StringLeft($read3,1))=="0" Or String(StringLeft($read3,1))=="." Then
    GUICtrlSetData($Input04,StringRegExpReplace($read3,'^0+|^\.+',''))
Else
    $write=StringRegExpReplace($read3,'[^\.0-9]+','')
    $temp=StringSplit($write,".",1+2)
If UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
    GUICtrlSetData($Input04,$write)
EndIf
   If StringLeft($read3,4)>30 Then 
MsgBox(16,"提示","输入错误,请输入小于或等于30的数")
GUICtrlSetData($Input04,"")
   EndIf
EndFunc
;----------------------------------限制能力素质输入框的首位不能为“0”、“.”及不能大于30
Func daochu()                  ;---导出表格函数
        Local $array[1]
For $i = 0 To UBound($List) - 1
        $Count = _GUICtrlListView_GetItemCount($List[$i])
_ArrayAdd($array, $Test[$i])
        If $Count <> 0 Then
For $ii = 0 To $Count - 1
        _ArrayAdd($array, _GUICtrlListView_GetItemTextString($List[$i],$ii))
        Next
EndIf
        Next
$excel = _ExcelBookNew(1)  ;创建一个新的工作表并设置显示,(0=不可见, 1=可见)
        For $i = 1 To UBound($array) - 1   ;返回数组维度的大小
$htest = StringSplit($array[$i], "|")  ;以指定分隔符把字符串拆分成若干子串
        For $ii = 0 To $htest[0]
_ExcelWriteCell($excel, $htest[$ii], $i, $ii)
   Next
Next
        EndFunc         

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-12-28 15:06:53 | 显示全部楼层
 楼主| 发表于 2011-12-28 15:39:51 | 显示全部楼层
回复 2# amxi

      非常感谢!以总分升序或降序排列已经实现,但后面的德育素质排名、智育素质排名及能力素质的排名有些麻烦。
发表于 2011-12-28 17:21:24 | 显示全部楼层
都是同一行的,排序也只能按一个标准来做,多个标准反而看不明白。
发表于 2011-12-28 17:54:41 | 显示全部楼层
Excel 可以附加第 2,3 。。。。排序, au3 可能困难,没研究过。。。。
发表于 2011-12-28 21:36:09 | 显示全部楼层
回复 2# amxi


    xie谢了!!
发表于 2012-1-3 10:09:36 | 显示全部楼层
ListViewEditEvent.au3呢?呵呵
发表于 2012-1-3 10:11:57 | 显示全部楼层
找到哈,加个LVS_SORTASCENDING吧
发表于 2012-1-3 10:36:42 | 显示全部楼层
多谢楼主共享,支持你
发表于 2012-1-4 09:29:29 | 显示全部楼层
学习一下!
发表于 2012-1-4 14:08:23 | 显示全部楼层
学习一下!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 14:11 , Processed in 0.089663 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表