Simpel

[Work around] _GUICtrlListView_InsertItem: delimiter ignored

2 posts in this topic

#1 ·  Posted (edited)

Hi.

I want to change item order with drag and drop using this script:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1);
GUICreate("_GUICtrlListView_InsertItem-Delimiter-Problem", 824 , 530)
GUISetFont(14)
Global $g_hListView = GUICtrlCreateListView("1|2|3|4", 10, 10, 804, 500)
For $i = 0 To 5
    GUICtrlCreateListViewItem("1|2|3|4", $g_hListView)
Next
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 3, 200)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"_Arrange_List")
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUISetState(@SW_SHOW)
While 1
    Sleep(10)
WEnd

Func _Arrange_List()
    Local $Selected = _GUICtrlListView_GetHotItem($g_hListView)
    If $Selected = -1 Then Return
    While _IsPressed(1)
    WEnd
    Local $Dropped = _GUICtrlListView_GetHotItem($g_hListView)
    If $Dropped > -1 Then
        ConsoleWrite(_GUICtrlListView_GetItemTextString($g_hListView, $Selected) & @CRLF)
        _GUICtrlListView_BeginUpdate($g_hListView)
        If $Selected < $Dropped Then
            _GUICtrlListView_InsertItem($g_hListView, _GUICtrlListView_GetItemTextString($g_hListView, $Selected), $Dropped + 1) ; ignores delimiter |
            _GUICtrlListView_DeleteItem($g_hListView, $Selected)
        ElseIf $Selected > $Dropped Then
            _GUICtrlListView_InsertItem($g_hListView, _GUICtrlListView_GetItemTextString($g_hListView, $Selected), $Dropped) ; ignores delimiter |
            _GUICtrlListView_DeleteItem($g_hListView, $Selected + 1)
        EndIf
        _GUICtrlListView_EndUpdate($g_hListView)
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

But if I drag and drop a row the whole text of the complete item including | is inserted in the first subitem.

Any suggestions? Conrad

Edited by Simpel
[work around]

SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Found a work around with _GUICtrlListView_SetItemText ( $hWnd, $iIndex, $sText [, $iSubItem = 0] ) and $iSubItem with -1 (undocumented):

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1);
GUICreate("_GUICtrlListView_InsertItem-Delimiter-Problem", 824 , 530)
GUISetFont(14)
Global $g_hListView = GUICtrlCreateListView("1|2|3|4", 10, 10, 804, 500)
For $i = 1 To 5
    GUICtrlCreateListViewItem($i * 1 & "|" & $i * 2 & "|" & $i * 3 & "|" & $i * 4, $g_hListView)
Next
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 3, 200)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"_Arrange_List")
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUISetState(@SW_SHOW)
While 1
    Sleep(10)
WEnd

Func _Arrange_List()
    Local $Selected = _GUICtrlListView_GetHotItem($g_hListView)
    If $Selected = -1 Then Return
    While _IsPressed(1)
    WEnd
    Local $Dropped = _GUICtrlListView_GetHotItem($g_hListView)
    If $Dropped > -1 Then
        ConsoleWrite(_GUICtrlListView_GetItemTextString($g_hListView, $Selected) & @CRLF)
        _GUICtrlListView_BeginUpdate($g_hListView)
        If $Selected < $Dropped Then
            _GUICtrlListView_InsertItem($g_hListView, "", $Dropped + 1)
            _GUICtrlListView_SetItemText($g_hListView, $Dropped +1, _GUICtrlListView_GetItemTextString($g_hListView, $Selected), -1)
            _GUICtrlListView_DeleteItem($g_hListView, $Selected)
        ElseIf $Selected > $Dropped Then
            _GUICtrlListView_InsertItem($g_hListView, "", $Dropped)
            _GUICtrlListView_SetItemText($g_hListView, $Dropped, _GUICtrlListView_GetItemTextString($g_hListView, $Selected + 1), -1)
            _GUICtrlListView_DeleteItem($g_hListView, $Selected + 1)
        EndIf
        _GUICtrlListView_EndUpdate($g_hListView)
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

Conrad

Edited by Simpel
typo

SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
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