styledream 发表于 2010-11-11 11:34:32

用_GUICtrlListView_InsertGroup插入组名后排序混乱

本帖最后由 styledream 于 2010-11-11 11:40 编辑

创建了一个列表后,从数据文件中读取组名并插入,如图:

第一次加载数据时组名时显示正确


点击Button加载其它数据时组名就有点混乱了


由于对InsertGroup的使用不是很熟悉,看了许久的代码,仍然无法解决此问题{:face (245):}
以下是关键源码:
Func CreateListView()   ;创建列表
        ;Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
        Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_TRACKSELECT, $LVS_EX_SUBITEMIMAGES)
        $hListView = _GUICtrlListView_Create($myGUI, "", 126, 77, 467, 325, -1, -1, True) ; 最后一个选项调用 CoIn
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)
        ;Local $hListView = GUICtrlCreateListView("", 154, 40, 510, 406, $LVS_NOSORTHEADER, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_TRACKSELECT))

        ; 加载图像
        $hImage = _GUIImageList_Create(16, 16, 5, 3)
        _GUIImageList_AddBitmap($hImage, '.\ico.bmp')
        _GUICtrlListView_SetImageList($hListView, $hImage, 1)

        ; 添加列
        _GUICtrlListView_InsertColumn($hListView, 0, "菜名", 120)
        _GUICtrlListView_InsertColumn($hListView, 1, "价格", 100)
        _GUICtrlListView_InsertColumn($hListView, 2, "菜名", 105)
        _GUICtrlListView_InsertColumn($hListView, 3, "价格", 125)

        ; 为列表视图控件分配100项目内存
        _GUICtrlListView_SetItemCount($hListView, 100)
       
        ; 添加项目
        LoadListView("咸骨粥")
EndFunc   ;==>CreateListView

Func LoadListView($sj)   ;加载数据到列表中
        ; 清除所有项目
        _GUICtrlListView_DeleteAllItems($hListView)
                       
        ; 添加项目
        Dim $myArray, $rows = 0
        Dim $count = 0, $line = 0, $nums = 0
        $myArray = IniReadSection(".\Food.dat", $sj)
        _GUICtrlListView_BeginUpdate($hListView)

               
        For $k = $myArray To 1 Step -1 ;倒序添加项目,使组名正序

                ; 分离值
                $aItems = StringSplit($myArray[$k], "|")
                $line = Int($aItems / 4)
                If (Mod($aItems, 4) <> 0) Then $line += 1
                $nums = 1

                ; 添加列表项目
                For $j = 1 To $line
                        _GUICtrlListView_AddItem($hListView, $aItems[$nums])

                        For $p = $nums + 1 To $nums + 3
                                If ($p <= $aItems) Then
                                        _GUICtrlListView_AddSubItem($hListView, $rows, $aItems[$p], $p - $nums)
                                EndIf
                        Next

                        $rows += 1
                        $nums += 4
                Next

                ; 建立组
                _GUICtrlListView_EnableGroupView($hListView)
                _GUICtrlListView_InsertGroup($hListView, 0, $k, $myArray[$k])
                ;MsgBox(0,"","$k="&$k &@CRLF& "Name="&$myArray[$k])

                ; 添加组项目
                For $i = 0 To $line - 1
                        _GUICtrlListView_SetItemGroupID($hListView, $count, $k)
                        $count = $count + 1
                Next
               
                _GUICtrlListView_EndUpdate($hListView)
        Next
       
EndFunc   ;==>LoadListView另外,列表头是否有美化的函数

mo_shaojie 发表于 2010-11-11 13:40:29

呵呵,这个界面看似不错的.

3mile 发表于 2010-11-11 15:24:31

代码未看。但只是猜想,可否将不同分组定义不同数组以方便管理。

3131806 发表于 2010-11-11 20:46:28

代码我执行后是报错的!

yyy910 发表于 2010-11-11 21:06:46

看起来不错,支持一下。

newuser 发表于 2010-11-12 08:07:57

回复 1# styledream
不知道能否放出完整代码以便于学习,谢谢!

styledream 发表于 2010-11-28 11:37:04

回复 6# newuser

现在就差这个错误没搞定,把它完善了,就放出源码共享~~~

newuser 发表于 2010-11-29 13:50:18

回复 7# styledream
谢谢,祝早日成功!
页: [1]
查看完整版本: 用_GUICtrlListView_InsertGroup插入组名后排序混乱