Jump to content

Recommended Posts

Posted

Hi

I am finding it difficult to use GuiCtrlSetData for GUICtrlCreateListViewItem. I could'nt understand it from the help file. Could someone help me out?

$INI = "test.ini"

;$Ini = "C:\SomePath\SomeFile.ini"

$aSecs = IniReadSectionNames($Ini)

$Main = GUICreate("Test GUI")

$Lv = GUICtrlCreateListView("Section|Key|Value",10,10,300, 300)

For $I = 1 To Ubound($aSecs) -1

$aVals = IniReadSection($Ini, $aSecs[$I])

For $X = 1 To Ubound($aVals) -1

$sVal = $aSecs[$i] & "|" & $aVals[$x][0] & "|" & $aVals[$x][1]

GUICtrlCreateListViewItem($sVal, $Lv)

Next

Next

GUISetState()

While 1

If GUIGetMsg() = -3 Then Exit

Wend

Thanks

Ajit

test.au3

Posted (edited)

Hi

I am finding it difficult to use GuiCtrlSetData for GUICtrlCreateListViewItem. I could'nt understand it from the help file. Could someone help me out?

$INI = "test.ini"

;$Ini = "C:\SomePath\SomeFile.ini"

$aSecs = IniReadSectionNames($Ini)

$Main = GUICreate("Test GUI")

$Lv = GUICtrlCreateListView("Section|Key|Value",10,10,300, 300)

For $I = 1 To Ubound($aSecs) -1

$aVals = IniReadSection($Ini, $aSecs[$I])

For $X = 1 To Ubound($aVals) -1

$sVal = $aSecs[$i] & "|" & $aVals[$x][0] & "|" & $aVals[$x][1]

GUICtrlCreateListViewItem($sVal, $Lv)

Next

Next

GUISetState()

While 1

If GUIGetMsg() = -3 Then Exit

Wend

Thanks

Ajit

You need to save the Control ID of each ListViewItem you create (I prefer in an array, but it doesn't have to be).

When you do GuiCtrlSetData() you will provide the Control ID of the item you want to change. To do that, you must have saved it when you created it.

#include <Array.au3>

Global $aSecs[4] = [3, "One", "Two", "Three"]
Global $aVals[4][2] = [[3, ""], ["Alpha", 1], ["Beta", 2], ["Gamma", 3]]
Global $aLVItems[1] = [0]

$Main = GUICreate("Test GUI")
$Lv = GUICtrlCreateListView("Section|Key|Value", 10, 10, 300, 300)

For $I = 1 To UBound($aSecs) - 1
    For $X = 1 To UBound($aVals) - 1
        $sVal = $aSecs[$I] & "|" & $aVals[$X][0] & "|" & $aVals[$X][1]
        $iLVItem = GUICtrlCreateListViewItem($sVal, $Lv)
        _ArrayAdd($aLVItems, $iLVItem); Save the Control ID for future reference
    Next
Next

GUISetState()

Sleep(5000)
; Change the text in the second item:
GUICtrlSetData($aLVItems[2], "My|New|Data")

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

:)

Edit: Added demo.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

You need to save the Control ID of each ListViewItem you create (I prefer in an array, but it doesn't have to be).

When you do GuiCtrlSetData() you will provide the Control ID of the item you want to change. To do that, you must have saved it when you created it.

#include <Array.au3>

Global $aSecs[4] = [3, "One", "Two", "Three"]
Global $aVals[4][2] = [[3, ""], ["Alpha", 1], ["Beta", 2], ["Gamma", 3]]
Global $aLVItems[1] = [0]

$Main = GUICreate("Test GUI")
$Lv = GUICtrlCreateListView("Section|Key|Value", 10, 10, 300, 300)

For $I = 1 To UBound($aSecs) - 1
    For $X = 1 To UBound($aVals) - 1
        $sVal = $aSecs[$I] & "|" & $aVals[$X][0] & "|" & $aVals[$X][1]
        $iLVItem = GUICtrlCreateListViewItem($sVal, $Lv)
        _ArrayAdd($aLVItems, $iLVItem); Save the Control ID for future reference
    Next
Next

GUISetState()

Sleep(5000)
; Change the text in the second item:
GUICtrlSetData($aLVItems[2], "My|New|Data")

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

:)

Edit: Added demo.

@PsaltyDS

Thanks very much for your help. Works perfect.

Thanks again.

Regards

Ajit

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
×
×
  • Create New...