Jump to content

How to use GUICtrlSetData for GUICtrlCreateListViewItem


ajit
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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...