Jump to content

Listview +$LVS_SORTASCENDING error


Recommended Posts

Hey,

I had created a listview with automatic sorting, but when i'm inserting an item, it will delete the seccond colum by some record.

I prefer not the command GUICtrlCreateListViewItem() because I have a list with a lot of items.

#NoTrayIcon
#include <GUIConstants.au3>
#include <GuiListView.au3>

$gui = GUICreate("List", 400, 400, 200, 100, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX, $WS_MAXIMIZEBOX))

$list = GUICtrlCreateListView("Proces|ID", 5, 5, 390, 390, $LVS_SHOWSELALWAYS+$LVS_SINGLESEL+$LVS_SORTASCENDING)

GUISetState()

$i_list = ProcessList()
For $n = 1 To $i_list[0][0]
    If $i_list[$n][0] <> "" AND $i_list[$n][1] <> "" Then _GUICtrlListViewInsertItem($list, -1, $i_list[$n][0]&"|"&$i_list[$n][1])
Next

_GUICtrlListViewSetColumnWidth($list, 0, 200)
_GUICtrlListViewSetColumnWidth($list, 1, 100)
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch
WEnd

Thanks, Ghastly_MIB

Link to comment
Share on other sites

Hey,

I had created a listview with automatic sorting, but when i'm inserting an item, it will delete the seccond colum by some record.

I prefer not the command GUICtrlCreateListViewItem() because I have a list with a lot of items.

#NoTrayIcon
#include <GUIConstants.au3>
#include <GuiListView.au3>

$gui = GUICreate("List", 400, 400, 200, 100, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX, $WS_MAXIMIZEBOX))

$list = GUICtrlCreateListView("Proces|ID", 5, 5, 390, 390, $LVS_SHOWSELALWAYS+$LVS_SINGLESEL+$LVS_SORTASCENDING)

GUISetState()

$i_list = ProcessList()
For $n = 1 To $i_list[0][0]
    If $i_list[$n][0] <> "" AND $i_list[$n][1] <> "" Then _GUICtrlListViewInsertItem($list, -1, $i_list[$n][0]&"|"&$i_list[$n][1])
Next

_GUICtrlListViewSetColumnWidth($list, 0, 200)
_GUICtrlListViewSetColumnWidth($list, 1, 100)
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch
WEnd

Thanks, Ghastly_MIB

Don't use $LVS_SORTASCENDING style if your going to be inserting items

also, you need to use BitOr($LVS_SHOWSELALWAYS,$LVS_SINGLESEL) for styles

i suggest doing a sort for example

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($list)]

GUICtrlListViewSort($listview, $B_DESCENDING, 0)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Don't use $LVS_SORTASCENDING style if your going to be inserting items

also, you need to use BitOr($LVS_SHOWSELALWAYS,$LVS_SINGLESEL) for styles

i suggest doing a sort for example

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($list)]

GUICtrlListViewSort($listview, $B_DESCENDING, 0)

Thats the problem, with _GUICtrlListViewSort it deletes all the items...

But i wan't u update it.

THe script i'm making is a realtime proces manager... So i wan't to update the list every second, but I don't wat to remove the list and sort it.

The adding and removing script is ready, but when it adds the new item to the list it apears on top.

So i would like to sort the list directly so it don't have to delete, add en sort the items...

So isn't there an other way? :o

Thanks, Ghastly_MIB

Link to comment
Share on other sites

Thats the problem, with _GUICtrlListViewSort it deletes all the items...

But i wan't u update it.

THe script i'm making is a realtime proces manager... So i wan't to update the list every second, but I don't wat to remove the list and sort it.

The adding and removing script is ready, but when it adds the new item to the list it apears on top.

So i would like to sort the list directly so it don't have to delete, add en sort the items...

So isn't there an other way? :o

Thanks, Ghastly_MIB

My suggestion then would be to just use the the GuiCtrlCreateListViewItem, that will add the item, and the sort style will reorder it

#include <GuiConstants.au3>
#include <GuiListView.au3>

opt('MustDeclareVars', 1)
Dim $listview, $Btn_Exit, $msg
GUICreate("ListView", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149, BitOR($LVS_SORTASCENDING,$LVS_SHOWSELALWAYS, $LVS_SINGLESEL))
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("line1|data1|more1", $listview)
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
GUICtrlCreateListViewItem("line3|data3|more3", $listview)
GUICtrlCreateListViewItem("line4|data4|more4", $listview)
GUICtrlCreateListViewItem("line5|data5|more5", $listview)
_GUICtrlListViewSetColumnWidth ($listview, 0, 75)
_GUICtrlListViewSetColumnWidth ($listview, 1, 75)
_GUICtrlListViewSetColumnWidth ($listview, 2, 75)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)

GUISetState()
Sleep( 3000 )
GUICtrlCreateListViewItem("line2.5|data5|more5", $listview)

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
         ExitLoop
   EndSelect
WEnd
Exit
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...