Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz
  • 0

Jak zapisać kilka 'itemów' do jednej zmiennej tablicowej


verssusspl

Pytanie

Opublikowano

Witam po latach. 
Po tym, jak dokonałem „wielu” modyfikacji mojego GUI, nadal potrzebuję pomocy w rozwiązaniu mojego problemu.
to jak przechowywać kilka elementów z tekstem w zmiennych tablicowych.
Zaznaczam, że nigdy wcześniej nie używałem zmiennych tablicowych i ciężko mi ich poprawnie używac
 

Spoiler

#include <FileConstants.au3>
#include <ListViewConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <GuiImageList.au3>
#include <SendMessage.au3>
#include <Misc.au3>
#include <GuiEdit.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <AutoItConstants.au3>

$GUI = GUICreate("gui")
GUISetState()

$ListView = GUICtrlCreateListView("Name1|Name2|Surrealneme3|", 10, 10, 250, 350, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($ListView, 10, 0)
$LV = GUICtrlGetHandle($ListView)

For $i = 0 To 9
        GUICtrlCreateListViewItem("name" & $i & "|surname" & $i & "|surrealizm" & $i, $ListView)
Next
Global $var = _GUICtrlListView_GetSelectedIndices($LV)
$menu_file = GUICtrlCreateMenu("File")
$menu_file_save = GUICtrlCreateMenuItem("Save Settings", $menu_file)
$menu_file_load = GUICtrlCreateMenuItem("Load Settings", $menu_file)
$menu_file_exit = GUICtrlCreateMenuItem("Exit", $menu_file)
GUICtrlCreateMenuItem("", $menu_file)

$button_up = GUICtrlCreateButton("UP", 300, 10, 70, 25)
$button_down = GUICtrlCreateButton("DOWN", 300, 40, 70, 25)
$button_copy = GUICtrlCreateButton("Copy", 300, 70, 70, 25)
$button_paste = GUICtrlCreateButton("Paste", 300, 100, 70, 25)
$button_selectall = GUICtrlCreateButton("Select All", 300, 130, 70, 25)
$button_del_selected = GUICtrlCreateButton("DEL", 300, 160, 70, 25)
$button_exit = GUICtrlCreateButton("Exit", 300, 200, 70, 30)


While 1
	Switch GUIGetMsg()
		Case $button_exit,$menu_file_exit, $GUI_EVENT_CLOSE
			Exit

		Case $menu_file_save
            $index = _GUICtrlListView_GetItemCount($listview)
            $file_save = FileSaveDialog("Choose a filename.", "", "Data (*.ini)", $FD_PROMPTOVERWRITE, $FD_PATHMUSTEXIST)
            For $i = 0 To _GUICtrlListView_GetItemCount($listview) -1 step 1
                IniWrite($file_save, "procedura", $i, _
				_GUICtrlListView_GetItemText($ListView, $i, 0) & "|" & _
                _GUICtrlListView_GetItemText($ListView, $i, 1) & "|" & _
                _GUICtrlListView_GetItemText($ListView, $i, 2))
            Next
            IniWrite($file_save, "procedura", "index",$index )

        Case $menu_file_load
            $file_load = FileOpenDialog("Choose a filename.", "", "Data (*.ini)", $FD_PATHMUSTEXIST)
            $List = IniRead ( $file_load,"procedura","index","" )
                For $i = 0 To $List - 1
                    GUICtrlCreateListViewItem(IniRead ( $file_load,"procedura",$i,""),$ListView)
                Next

		Case $button_up ; how to move more then 1 selected item
			if _GUICtrlListView_GetSelectedIndices($LV) = 0 then
				_GUICtrlListView_ClickItem($listview,0,"left",False)
				MsgBox(0,"Error", "Cant Move This Item Up")
			Else
				Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
				Local $txt_at_bottom[_GUICtrlListView_GetColumnCount($LV)+1]
				$count_column = _GUICtrlListView_GetColumnCount($LV)
				$var = _GUICtrlListView_GetSelectedIndices($LV)
				_GUICtrlListView_ClickItem($listview,$var-1,"left",False)
				For $i = 0 To $count_column Step + 1
					$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,$var,$i)
					$txt_at_bottom[$i] = _GUICtrlListView_GetItemText($LV,$var-1,$i)
					_GUICtrlListView_SetItemText($LV, $var - 1, $txt_selected[$i],$i)
					_GUICtrlListView_SetItemText($LV, $var, $txt_at_bottom[$i],$i)
				Next
			EndIf

		Case $button_down ; how to move more then 1 selected item
			if _GUICtrlListView_GetSelectedIndices($LV) + 1 = _GUICtrlListView_GetItemCount($LV) then
				_GUICtrlListView_ClickItem($listview,0,"left",False)
				MsgBox(0,"Error", "Cant Move This Item Down")
			Else
				Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
				Local $txt_at_top[_GUICtrlListView_GetColumnCount($LV)+1]
				$count_column = _GUICtrlListView_GetColumnCount($LV)
				$var = _GUICtrlListView_GetSelectedIndices($LV)
				_GUICtrlListView_ClickItem($listview,$var+1,"left",False)
				For $i = 0 To $count_column Step + 1
					$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,$var,$i)
					$txt_at_top[$i] = _GUICtrlListView_GetItemText($LV,$var+1,$i)
					_GUICtrlListView_SetItemText($LV, $var + 1, $txt_selected[$i],$i)
					_GUICtrlListView_SetItemText($LV, $var, $txt_at_top[$i],$i)
				Next
			EndIf
		Case $button_selectall
			_GUICtrlListView_SetItemSelected($Listview, -1,true,True)
			_GUICtrlListView_ClickItem($listview, _GUICtrlListView_GetItemCount($LV),"left",False)

		Case $button_del_selected
			$var = _GUICtrlListView_GetSelectedIndices($listview)
			If $var = 0 Then
				_GUICtrlListView_DeleteItemsSelected($ListView)
				_GUICtrlListView_ClickItem($listview,$var,"left",False)
			Else
				_GUICtrlListView_DeleteItemsSelected($ListView)
				_GUICtrlListView_ClickItem($listview,$var-1,"left",False)
			EndIf

		Case $button_copy ; how to modify it to store more then 1 selected item
			Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
			$count_column = _GUICtrlListView_GetColumnCount($LV)
			For $i = 0 To $count_column Step + 1
				$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,_GUICtrlListView_GetSelectedIndices($LV),$i)
			Next

		Case $button_paste ; how to paste more then 1 item
			$var = _GUICtrlListView_GetSelectedIndices($listview)
			_GUICtrlListView_InsertItem($LV,$txt_selected[0], $var +1)
			For $i = 1 To $count_column
				_GUICtrlListView_AddSubItem($LV, $var +1, $txt_selected[$i],$i)
			Next
			_GUICtrlListView_ClickItem($listview,$var +1,"left",False)
	EndSwitch
WEnd

ew jakies sugestie co jest niw tak w innych częściach skryptu

10 odpowiedzi na to pytanie

Rekomendowane odpowiedzi

Opublikowano

//Proszę o umieszczanie dłuższego kodu w spoilerach - Pozdrawiam @carbonx ~ moderator N. Programisty

 

Wasta jetem ci wdzieczny za pomoc o to co otrzymalem po kilku dniowych modyfikacjach kodu
moje pierwsza w zyciu zmienna 2D 😛

 

Spoiler

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

$GUI = GUICreate("gui")
GUISetState()

$ListView = GUICtrlCreateListView("Name1|Name2|Surrealneme3|", 10, 10, 250, 350, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($ListView, 10, 0)
$LV = GUICtrlGetHandle($ListView)

For $i = 0 To 9
	GUICtrlCreateListViewItem("name" & $i & "|surname" & $i & "|surrealizm" & $i, $ListView)
Next

$button_copy = GUICtrlCreateButton("Copy", 300, 70, 70, 25)
$button_paste = GUICtrlCreateButton("Paste", 300, 100, 70, 25)
$button_exit = GUICtrlCreateButton("Exit", 300, 200, 70, 30)

While 1
	Switch GUIGetMsg()
		Case $button_exit, $GUI_EVENT_CLOSE
			Exit

		Case $button_copy ; how to modify it to store more then 1 selected item
			Local $Selected[_GUICtrlListView_GetSelectedCount($LV)][_GUICtrlListView_GetColumnCount($LV)]
			$k = -1
			For $i = 0 To _GUICtrlListView_GetitemCount($LV)-1
				If _GUICtrlListView_GetItemSelected($LV, $i) Then
					$k +=1
					For $j = 0 To _GUICtrlListView_GetColumnCount($LV) - 1
						$Selected[$k][$j] = _GUICtrlListView_GetItemText($LV, $i, $j)
					Next
				EndIf
			Next

		Case $button_paste
			$var = _GUICtrlListView_GetSelectionMark($LV)
			For $i = 0 To UBound($Selected)-1
				_GUICtrlListView_InsertItem($LV,$Selected[$i][0],$var+$i+1)
				For $j = 0 To _GUICtrlListView_GetColumnCount($LV) - 1
					_GUICtrlListView_AddSubItem($LV, $var+$i+1, $Selected[$i][$j], $j)
				Next
			Next
			_GUICtrlListView_ClickItem($LV,$var + UBound($Selected))
	EndSwitch
WEnd

polecam sie na przyszlosc

Opublikowano

Zobacz, czy o to ci chodziło?

Spoiler

#include <FileConstants.au3>
#include <ListViewConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <GuiImageList.au3>
#include <SendMessage.au3>
#include <Misc.au3>
#include <GuiEdit.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <AutoItConstants.au3>

Global $aSelectedItem


$GUI = GUICreate("gui")
GUISetState()

$ListView = GUICtrlCreateListView("Name1|Name2|Surrealneme3|", 10, 10, 250, 350, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($ListView, 10, 0)
$LV = GUICtrlGetHandle($ListView)

For $i = 0 To 9
        GUICtrlCreateListViewItem("name" & $i & "|surname" & $i & "|surrealizm" & $i, $ListView)
Next
Global $var = _GUICtrlListView_GetSelectedIndices($LV)
$menu_file = GUICtrlCreateMenu("File")
$menu_file_save = GUICtrlCreateMenuItem("Save Settings", $menu_file)
$menu_file_load = GUICtrlCreateMenuItem("Load Settings", $menu_file)
$menu_file_exit = GUICtrlCreateMenuItem("Exit", $menu_file)
GUICtrlCreateMenuItem("", $menu_file)

$button_up = GUICtrlCreateButton("UP", 300, 10, 70, 25)
$button_down = GUICtrlCreateButton("DOWN", 300, 40, 70, 25)
$button_copy = GUICtrlCreateButton("Copy", 300, 70, 70, 25)
$button_paste = GUICtrlCreateButton("Paste", 300, 100, 70, 25)
$button_selectall = GUICtrlCreateButton("Select All", 300, 130, 70, 25)
$button_del_selected = GUICtrlCreateButton("DEL", 300, 160, 70, 25)
$button_exit = GUICtrlCreateButton("Exit", 300, 200, 70, 30)

While 1
	Switch GUIGetMsg()
		Case $button_exit,$menu_file_exit, $GUI_EVENT_CLOSE
			Exit

		Case $menu_file_save
            $index = _GUICtrlListView_GetItemCount($listview)
            $file_save = FileSaveDialog("Choose a filename.", "", "Data (*.ini)", $FD_PROMPTOVERWRITE, $FD_PATHMUSTEXIST)
            For $i = 0 To _GUICtrlListView_GetItemCount($listview) -1 step 1
                IniWrite($file_save, "procedura", $i, _
				_GUICtrlListView_GetItemText($ListView, $i, 0) & "|" & _
                _GUICtrlListView_GetItemText($ListView, $i, 1) & "|" & _
                _GUICtrlListView_GetItemText($ListView, $i, 2))
            Next
            IniWrite($file_save, "procedura", "index",$index )

        Case $menu_file_load
            $file_load = FileOpenDialog("Choose a filename.", "", "Data (*.ini)", $FD_PATHMUSTEXIST)
            $List = IniRead ( $file_load,"procedura","index","" )
                For $i = 0 To $List - 1
                    GUICtrlCreateListViewItem(IniRead ( $file_load,"procedura",$i,""),$ListView)
                Next

		Case $button_up ; how to move more then 1 selected item
			if _GUICtrlListView_GetSelectedIndices($LV) = 0 then
				_GUICtrlListView_ClickItem($listview,0,"left",False)
				MsgBox(0,"Error", "Cant Move This Item Up")
			Else
				Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
				Local $txt_at_bottom[_GUICtrlListView_GetColumnCount($LV)+1]
				$count_column = _GUICtrlListView_GetColumnCount($LV)
				$var = _GUICtrlListView_GetSelectedIndices($LV)
				_GUICtrlListView_ClickItem($listview,$var-1,"left",False)
				For $i = 0 To $count_column Step + 1
					$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,$var,$i)
					$txt_at_bottom[$i] = _GUICtrlListView_GetItemText($LV,$var-1,$i)
					_GUICtrlListView_SetItemText($LV, $var - 1, $txt_selected[$i],$i)
					_GUICtrlListView_SetItemText($LV, $var, $txt_at_bottom[$i],$i)
				Next
			EndIf

		Case $button_down ; how to move more then 1 selected item
			if _GUICtrlListView_GetSelectedIndices($LV) + 1 = _GUICtrlListView_GetItemCount($LV) then
				_GUICtrlListView_ClickItem($listview,0,"left",False)
				MsgBox(0,"Error", "Cant Move This Item Down")
			Else
				Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
				Local $txt_at_top[_GUICtrlListView_GetColumnCount($LV)+1]
				$count_column = _GUICtrlListView_GetColumnCount($LV)
				$var = _GUICtrlListView_GetSelectedIndices($LV)
				_GUICtrlListView_ClickItem($listview,$var+1,"left",False)
				For $i = 0 To $count_column Step + 1
					$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,$var,$i)
					$txt_at_top[$i] = _GUICtrlListView_GetItemText($LV,$var+1,$i)
					_GUICtrlListView_SetItemText($LV, $var + 1, $txt_selected[$i],$i)
					_GUICtrlListView_SetItemText($LV, $var, $txt_at_top[$i],$i)
				Next
			EndIf
		Case $button_selectall
			_GUICtrlListView_SetItemSelected($Listview, -1,true,True)
			_GUICtrlListView_ClickItem($listview, _GUICtrlListView_GetItemCount($LV),"left",False)

		Case $button_del_selected
			$var = _GUICtrlListView_GetSelectedIndices($listview)
			If $var = 0 Then
				_GUICtrlListView_DeleteItemsSelected($ListView)
				_GUICtrlListView_ClickItem($listview,$var,"left",False)
			Else
				_GUICtrlListView_DeleteItemsSelected($ListView)
				_GUICtrlListView_ClickItem($listview,$var-1,"left",False)
			EndIf

		Case $button_copy ; how to modify it to store more then 1 selected item
			CopySelectedItem()

		Case $button_paste ; how to paste more then 1 item
			If IsArray($aSelectedItem) Then _GUICtrlListView_AddArray($LV, $aSelectedItem)

	EndSwitch
WEnd


Func CopySelectedItem()
	Local $aTemp[_GUICtrlListView_GetSelectedCount($LV)]
	$j=-1
	For $i=0 To _GUICtrlListView_GetItemCount($LV)
		If _GUICtrlListView_GetItemSelected($LV, $i) Then
			$j+=1
			$aTemp[$j] = _GUICtrlListView_GetItemTextArray($LV, $i)
		EndIf
	Next
	Local $iDim1 = UBound($aTemp)
	Local $iDim2 = UBound($aTemp[0])
	Global $aSelectedItem[$iDim1][$iDim2]
	For $i=0 to $iDim1-1
		For $j=0 To $iDim2-2
			$aTemp2 = $aTemp[$i]
			$aSelectedItem[$i][$j] = $aTemp2[$j+1]
		Next
	Next
EndFunc

 

Opublikowano

OK. Uzyskałeś prawie to co ja, z małą różnicą, że twój kod kopiuje za zaznaczonym wierszem, a mój przed nim. Ale to rzecz gustów, lub potrzeb.

Mam tylko dwie małe uwagi do twojego kodu. Nie chodzi tu o poprawność działanie, a pewną jego organizację.

Pierwsza uwaga to sprawa nazewnictwa zmiennych. Bardzo pomocną zasadą jest stosowanie prefiksu przy nazwach zmiennych. Np. zmienna tablicowa, to $aJakas_nazwa, Tekst to $sJakas_nazwa, uchwyt to $hJakas_nazwa, itd. Pozwala to na uniknięcie wielu błędów, takich jak np. użycie uchwytów  czy tablic w działaniach arytmetycznych. Popatrz w moim podręczniku do AutoIt'a: https://pl.wikibooks.org/wiki/AutoIt/Biblioteki.

Druga uwaga dotyczy organizacji kodu. Nie staraj się pakować wszystkiego do segmentu głównego programu. Pętla sterująca robi się tak duża i skomplikowana, że trudno pojąć, co się w niej właściwie dzieje. O wiele lepiej jest podzielić kod na funkcje, a w segmencie głównym wywoływać te funkcje (tak jak ja to zrobiłem w swojej propozycji).

Uwierz mi, tak jest o wiele wygodniej i przejrzyściej.  Po pewnym czasie, nawet własny kod napisany niezbyt przejrzyście, jest trudny do analizy, poprawiania i rozbudowy. Jak go podzielisz na mniejsze funkcje wykonujące jakieś konkretne i stosunkowo proste działanie, to będzie ci o wiele prościej analizować własny kod, gdy po jakimś czasie do niego wrócisz. Nie bój się funkcji, one nie gryzą, a pomagają!

Dobrze jest też komentować co trudniejsze fragmenty.

 

Pozdrawiam i życzę wielu przyjemności związanych z tworzeniem własnych programów.

Dla demonstracji, jak w AutoIt można robić w prosty sposób fajne, nieźle wyglądające i użyteczne rzeczy, wstawiam popełniony przeze mnie transparentny zegarek z kalendarzem.

Można go ustawić w dowolnym miejscu ekranu, za pomocą myszki (drag & drop). Pozycja jest zapamiętywana w pliku INI.

Zegar transparentny 3.0.zip

 

//dodane przez @carbonx

Skan:

https://www.virustotal.com/gui/file/d4eb8f363c5906038a0a2baaad81c3b0980d1d940ffeb47328d06bd1d06e709e/detection

[4/61] - raczej false positive

//

Opublikowano

dzieki za uwagi wezme je do siebie
a kwestia innego rozwiazania to bardziej proba treningu na zmiennych tablicowych ktore sa jednym z bardziej zaawanowana czescia autoit

 

Opublikowano

Wszystko co potrzebujesz wiedzieć na temat Array'ów znajdziesz na tej stronie https://www.autoitscript.com/wiki/Arrays

 

 

W autoit tworzy się tak samo jak zmienne tylko po nazwie dodajesz [rozmiar array'a].

 

Przykład array'a Local $arr[3] = ["element 1", "element 2", "element 3"]

 

Możesz też dodać więcej wartości w ten sposób $arr[3] = "element 4"

Opublikowano

znam podstawy ktore zaprezentowalem w skrypcie powyzej
i faktem jest ze zrozmiaru tej zmiennej wcale nie trzeba deklarowac
 

Spoiler

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Array.au3> ; Just for the demonstration

HotKeySet("{F2}", "_xxx")

Global $asdf[10] 
$q = 0

$GUI = GUICreate("gui", 670, 500)

$ListView = GUICtrlCreateListView("Name|No Name|Surrname|Next Name|U cant do it name", 10, 200, 450, 250,$LVS_SHOWSELALWAYS)
$LV = GUICtrlGetHandle($ListView)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If $q = UBound($asdf) Then
        ReDim  $asdf[$q +100]
        _ArrayDisplay($asdf, "", Default, 8)
    EndIf
    WEnd

Func _xxx()
    HotKeySet("{F2}")
    $var2 = _GUICtrlListView_GetSelectedIndices($LV)
    $asdf[$q] = _GUICtrlListView_InsertItem($LV,"Name "& $q, $var2 + 1)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "IS", 1)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "THIS", 2)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "WROKING", 3)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "RIGHT", 4)
    _GUICtrlListView_setItemSelected($LV, $asdf[$q], True)
    _GUICtrlListView_setItemSelected($LV, $asdf[$q] - 1, False)
    $q = $q + 1
    HotKeySet("{F2}", "_xxx")
EndFunc

ale nie o tym tutaj mowa
w zapytaniu  jest jesno napisane z czym mam problem

Opublikowano
Dnia 7.05.2020 o 23:59, verssusspl napisał:

znam podstawy ktore zaprezentowalem w skrypcie powyzej
i faktem jest ze zrozmiaru tej zmiennej wcale nie trzeba deklarowac
 

Spoiler


#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Array.au3> ; Just for the demonstration

HotKeySet("{F2}", "_xxx")

Global $asdf[10] 
$q = 0

$GUI = GUICreate("gui", 670, 500)

$ListView = GUICtrlCreateListView("Name|No Name|Surrname|Next Name|U cant do it name", 10, 200, 450, 250,$LVS_SHOWSELALWAYS)
$LV = GUICtrlGetHandle($ListView)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If $q = UBound($asdf) Then
        ReDim  $asdf[$q +100]
        _ArrayDisplay($asdf, "", Default, 8)
    EndIf
    WEnd

Func _xxx()
    HotKeySet("{F2}")
    $var2 = _GUICtrlListView_GetSelectedIndices($LV)
    $asdf[$q] = _GUICtrlListView_InsertItem($LV,"Name "& $q, $var2 + 1)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "IS", 1)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "THIS", 2)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "WROKING", 3)
    _GUICtrlListView_AddSubItem($LV, $asdf[$q], "RIGHT", 4)
    _GUICtrlListView_setItemSelected($LV, $asdf[$q], True)
    _GUICtrlListView_setItemSelected($LV, $asdf[$q] - 1, False)
    $q = $q + 1
    HotKeySet("{F2}", "_xxx")
EndFunc

ale nie o tym tutaj mowa
w zapytaniu  jest jesno napisane z czym mam problem

Opisz dokładnie o co tobie chodzi. do konkretnych elementów w array'u odwółujesz się poprzez jego index, pierwszy element w tablicy ma zawsze index 0.



C-Arrays.jpg

 

 

 

Tutaj jest przykład jak rzeczywiście wyglądają twoje dane. A więc $asdf[0] = "jakis teks"    Przypisanie do arraya na indexie zero.

 

Zajrzyj w link, który ci podesłałem wyżej - myślę, że jest tam wszystko dostatecznie opisane jak pracować z tablicami;

Opublikowano

prawie o to mi chodzi. zauwazylem tylko ze _GUICtrlListView_AddArray wprowadza wczesniej zapamietane dane do listy zaczynajac od pierwszego indexu
co co narazie udalo mi sie wymajstrowac zeby wklejenie wczesniej skopppiowanych itemow mialo miejsce PO zzaselektowanym itemie
brakuje mi jeszcze kolejnego wymiaru zeby dodac subitemy
(co mi sie wydaje) Local $Selected[_GUICtrlListView_GetSelectedCount($LV)][_GUICtrlListView_GetColumnCount($LV)]

 

chyba ze jest mozliwosc wprowadzenia arraya w wybrane przez selecttitem miejsce a nie na poczatek listy
wielkie dzieku najbardziej mi pomogla ta linijka If _GUICtrlListView_GetItemSelected($LV, $i) Then

Spoiler

#include <FileConstants.au3>
#include <ListViewConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <GuiImageList.au3>
#include <SendMessage.au3>
#include <Misc.au3>
#include <GuiEdit.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <AutoItConstants.au3>

$GUI = GUICreate("gui")
GUISetState()

$ListView = GUICtrlCreateListView("Name1|Name2|Surrealneme3|", 10, 10, 250, 350, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($ListView, 10, 0)
$LV = GUICtrlGetHandle($ListView)

For $i = 0 To 9
        GUICtrlCreateListViewItem("name" & $i & "|surname" & $i & "|surrealizm" & $i, $ListView)
Next

$button_copy = GUICtrlCreateButton("Copy", 300, 70, 70, 25)
$button_paste = GUICtrlCreateButton("Paste", 300, 100, 70, 25)
$button_exit = GUICtrlCreateButton("Exit", 300, 200, 70, 30)

While 1
	Switch GUIGetMsg()
		Case $button_exit,$GUI_EVENT_CLOSE
			Exit

		Case $button_copy ; how to modify it to store more then 1 selected item
			Local $Selected[_GUICtrlListView_GetSelectedCount($LV)]
			$Size = _GUICtrlListView_GetItemCount($LV)
			$j=-1
			For $i = 0 To $Size Step + 1
				If _GUICtrlListView_GetItemSelected($LV, $i) Then
					$j+=1
					$Selected[$j] = _GUICtrlListView_GetItemText($LV, $i,0)
				EndIf
			Next

		Case $button_paste ; how to paste more then 1 item
			$var = _GUICtrlListView_GetSelectedIndices($listview)
			For $i=0 to UBound($Selected)-1
			_GUICtrlListView_InsertItem($LV,$Selected[$i],$var +1)
			$var += 1
			Next
	EndSwitch
WEnd

 

probuje cos takiego ale gdzies popelniam blad
 

Spoiler

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

$GUI = GUICreate("gui")
GUISetState()

$ListView = GUICtrlCreateListView("Name1|Name2|Surrealneme3|", 10, 10, 250, 350, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($ListView, 10, 0)
$LV = GUICtrlGetHandle($ListView)

For $i = 0 To 9
        GUICtrlCreateListViewItem("name" & $i & "|surname" & $i & "|surrealizm" & $i, $ListView)
Next

$button_copy = GUICtrlCreateButton("Copy", 300, 70, 70, 25)
$button_paste = GUICtrlCreateButton("Paste", 300, 100, 70, 25)
$button_exit = GUICtrlCreateButton("Exit", 300, 200, 70, 30)

While 1
	Switch GUIGetMsg()
		Case $button_exit,$GUI_EVENT_CLOSE
			Exit

		Case $button_copy ; how to modify it to store more then 1 selected item
			Global $Selected[_GUICtrlListView_GetSelectedCount($LV)][ _GUICtrlListView_GetColumnCount($LV)]
			$k=-1
			$l=-1
			For $i = 0 To _GUICtrlListView_GetItemCount($LV) Step +1
				If _GUICtrlListView_GetItemSelected($LV, $i) Then
					$k+=1
					For $j=0 to _GUICtrlListView_GetColumnCount($LV) Step +1
						$l+=1
						$Selected[$k][$l] = _GUICtrlListView_GetItemText($LV, $i,$j)
					Next
				EndIf
			Next

		Case $button_paste ; how to paste more then 1 item
			$var = _GUICtrlListView_GetSelectedIndices($listview)
			For $i=0 to UBound($Selected)-1
				_GUICtrlListView_InsertItem($LV,$Selected[$i],$var +1)
			$var += 1
			Next
	EndSwitch
WEnd

to jest to co chcialbym zeby zmienna zwracala 
$selected [0][0] text of index 0 item
$selected [0][1] text of index 0 subitem 1
$selected [0][2] text of index 0 subitem 1
$selected [1][0] text of index 1 item
$selected [1][0] text of index 1 item
$selected [1][1] text of index 1 subitem 1
$selected [1][2] text of index 1 subitem 2

jak to poprawnie zapisac ?

 

Opublikowano

dokladnie mi chodzi o to ze z posrod 10 itemow zaznaczam 3 5 8 i klikam copy potem paste i dokladnie te elementy ktore byly zaznaczone sie wklejaja.
znam ten link od dawna ale ale do mnie nie przemawia. potrzebuje prostego przykladu na podstawie jego jak to przedstawic 

 

chodzi to bankowo o prawidlowe uzycie _GUICtrlListView_GetSelectedIndices($LV) ktora zwraca zaznaczony index itemu jak jest zaznaczony jeden i 3|5|8 jak sa zaznaczone wyzej wymienione

 

Opublikowano

A teraz?

Spoiler

#include <FileConstants.au3>
#include <ListViewConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <GuiImageList.au3>
#include <SendMessage.au3>
#include <Misc.au3>
#include <GuiEdit.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <AutoItConstants.au3>

Global $aSelectedItem


$GUI = GUICreate("gui")
GUISetState()

$ListView = GUICtrlCreateListView("Name1|Name2|Surrealneme3|", 10, 10, 250, 350, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($ListView, 10, 0)
$LV = GUICtrlGetHandle($ListView)

For $i = 0 To 9
        GUICtrlCreateListViewItem("name" & $i & "|surname" & $i & "|surrealizm" & $i, $ListView)
Next
Global $var = _GUICtrlListView_GetSelectedIndices($LV)
$menu_file = GUICtrlCreateMenu("File")
$menu_file_save = GUICtrlCreateMenuItem("Save Settings", $menu_file)
$menu_file_load = GUICtrlCreateMenuItem("Load Settings", $menu_file)
$menu_file_exit = GUICtrlCreateMenuItem("Exit", $menu_file)
GUICtrlCreateMenuItem("", $menu_file)

$button_up = GUICtrlCreateButton("UP", 300, 10, 70, 25)
$button_down = GUICtrlCreateButton("DOWN", 300, 40, 70, 25)
$button_copy = GUICtrlCreateButton("Copy", 300, 70, 70, 25)
$button_paste = GUICtrlCreateButton("Paste", 300, 100, 70, 25)
$button_selectall = GUICtrlCreateButton("Select All", 300, 130, 70, 25)
$button_del_selected = GUICtrlCreateButton("DEL", 300, 160, 70, 25)
$button_exit = GUICtrlCreateButton("Exit", 300, 200, 70, 30)

While 1
	Switch GUIGetMsg()
		Case $button_exit,$menu_file_exit, $GUI_EVENT_CLOSE
			Exit

		Case $menu_file_save
            $index = _GUICtrlListView_GetItemCount($listview)
            $file_save = FileSaveDialog("Choose a filename.", "", "Data (*.ini)", $FD_PROMPTOVERWRITE, $FD_PATHMUSTEXIST)
            For $i = 0 To _GUICtrlListView_GetItemCount($listview) -1 step 1
                IniWrite($file_save, "procedura", $i, _
				_GUICtrlListView_GetItemText($ListView, $i, 0) & "|" & _
                _GUICtrlListView_GetItemText($ListView, $i, 1) & "|" & _
                _GUICtrlListView_GetItemText($ListView, $i, 2))
            Next
            IniWrite($file_save, "procedura", "index",$index )

        Case $menu_file_load
            $file_load = FileOpenDialog("Choose a filename.", "", "Data (*.ini)", $FD_PATHMUSTEXIST)
            $List = IniRead ( $file_load,"procedura","index","" )
                For $i = 0 To $List - 1
                    GUICtrlCreateListViewItem(IniRead ( $file_load,"procedura",$i,""),$ListView)
                Next

		Case $button_up ; how to move more then 1 selected item
			if _GUICtrlListView_GetSelectedIndices($LV) = 0 then
				_GUICtrlListView_ClickItem($listview,0,"left",False)
				MsgBox(0,"Error", "Cant Move This Item Up")
			Else
				Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
				Local $txt_at_bottom[_GUICtrlListView_GetColumnCount($LV)+1]
				$count_column = _GUICtrlListView_GetColumnCount($LV)
				$var = _GUICtrlListView_GetSelectedIndices($LV)
				_GUICtrlListView_ClickItem($listview,$var-1,"left",False)
				For $i = 0 To $count_column Step + 1
					$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,$var,$i)
					$txt_at_bottom[$i] = _GUICtrlListView_GetItemText($LV,$var-1,$i)
					_GUICtrlListView_SetItemText($LV, $var - 1, $txt_selected[$i],$i)
					_GUICtrlListView_SetItemText($LV, $var, $txt_at_bottom[$i],$i)
				Next
			EndIf

		Case $button_down ; how to move more then 1 selected item
			if _GUICtrlListView_GetSelectedIndices($LV) + 1 = _GUICtrlListView_GetItemCount($LV) then
				_GUICtrlListView_ClickItem($listview,0,"left",False)
				MsgBox(0,"Error", "Cant Move This Item Down")
			Else
				Local $txt_selected[_GUICtrlListView_GetColumnCount($LV)+1]
				Local $txt_at_top[_GUICtrlListView_GetColumnCount($LV)+1]
				$count_column = _GUICtrlListView_GetColumnCount($LV)
				$var = _GUICtrlListView_GetSelectedIndices($LV)
				_GUICtrlListView_ClickItem($listview,$var+1,"left",False)
				For $i = 0 To $count_column Step + 1
					$txt_selected[$i] = _GUICtrlListView_GetItemText($LV,$var,$i)
					$txt_at_top[$i] = _GUICtrlListView_GetItemText($LV,$var+1,$i)
					_GUICtrlListView_SetItemText($LV, $var + 1, $txt_selected[$i],$i)
					_GUICtrlListView_SetItemText($LV, $var, $txt_at_top[$i],$i)
				Next
			EndIf
		Case $button_selectall
			_GUICtrlListView_SetItemSelected($Listview, -1,true,True)
			_GUICtrlListView_ClickItem($listview, _GUICtrlListView_GetItemCount($LV),"left",False)

		Case $button_del_selected
			$var = _GUICtrlListView_GetSelectedIndices($listview)
			If $var = 0 Then
				_GUICtrlListView_DeleteItemsSelected($ListView)
				_GUICtrlListView_ClickItem($listview,$var,"left",False)
			Else
				_GUICtrlListView_DeleteItemsSelected($ListView)
				_GUICtrlListView_ClickItem($listview,$var-1,"left",False)
			EndIf

		Case $button_copy ; how to modify it to store more then 1 selected item
			CopySelectedItem()

		Case $button_paste ; how to paste more then 1 item
			PasteCopyItem()

	EndSwitch
WEnd

;------------------------------------------------------------------------------------------
Func CopySelectedItem()
	Local $aTemp[_GUICtrlListView_GetSelectedCount($LV)]
	$j=-1
	For $i=0 To _GUICtrlListView_GetItemCount($LV)
		If _GUICtrlListView_GetItemSelected($LV, $i) Then
			$j+=1
			$aTemp[$j] = _GUICtrlListView_GetItemTextArray($LV, $i)
		EndIf
	Next
	Local $iDim1 = UBound($aTemp)
	Local $iDim2 = UBound($aTemp[0])
	Global $aSelectedItem[$iDim1][$iDim2]
	For $i=0 to $iDim1-1
		For $j=0 To $iDim2-2
			$aTemp2 = $aTemp[$i]
			$aSelectedItem[$i][$j] = $aTemp2[$j+1]
		Next
	Next
EndFunc

;-------------------------------------------------------------------------------------------
Func PasteCopyItem()
	Local $aPos = _GUICtrlListView_GetSelectedIndices($LV, True)
	Local $iDim = UBound($aSelectedItem)
	Local $iDim1 = UBound($aSelectedItem, 2)
	For $i=$iDim-1 To 0 Step -1
		_GUICtrlListView_InsertItem($LV,$aSelectedItem[$i][0],$aPos[1])
		For $j=1 to $iDim1-2
			_GUICtrlListView_AddSubItem ($LV, $aPos[1], $aSelectedItem[$i][$j], $j)
		Next
	Next
EndFunc

 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...