Jump to content

Recommended Posts

Posted

Hello all.  I have a form which contains a listview control, and I want to be able to dynamically create listview items while assigning them to unique variables.  Kind of like something like this:

$listview = GUICtrlCreateListView ()
local $array[3][2]
$array[0][0] = "First"
$array[0][1] = "A value"
$array[1][0] = "Second"
$array[1][1] = "second value"
$array[2][0] = "Third"
$array[2][1] = "third value"
For $i = 0 to UBound ( $array, $UBOUND_ROWS ) - 1 Step 1
    $listviewitem$i = GUICtrlCreateListViewItem ( $array[$i][0] & "|" & $array[$i][1], $listview )
Next

 so the variable holding each listviewitem would be a variable that starts with "listview" and appends the integer stored in $i to the end to make that variable unique.  I would think that the function "assign" would be perfect for something like this, but the only examples I have seen where it is uses are for strings.  Is the below code possible?

$listview = GUICtrlCreateListView ()
local $array[3][2]
$array[0][0] = "First"
$array[0][1] = "A value"
$array[1][0] = "Second"
$array[1][1] = "second value"
$array[2][0] = "Third"
$array[2][1] = "third value"
For $i = 0 to UBound ( $array, $UBOUND_ROWS ) - 1 Step 1
    Assign ("listviewitem" & $i, GUICtrlCreateListViewItem ( $array[$i][0] & "|" & $array[$i][1], $listview ) )
Next

Would this successfully create variables $listviewitem0, $listviewitem1, $listviewitem2 like I am thinking it would, or would it blow up in my face?

Posted

Why don’t you use an array? That’s what they are made for. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I mean: Why create variables like $listviewitem0, $listviewitem1, $listviewitem2 when you can use an array like $listviewitem[0], $listviewitem[1], $listviewitem[2]?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

It is best, just like @water said, to place the listview items into their their own array.

As you already have created an array, the only thing you have to do, is to add the created item to it.

Change your script like this

local $array[3][3]
$array[0][1] = "First"
$array[0][2] = "A value"
$array[1][1] = "Second"
$array[1][2] = "second value"
$array[2][1] = "Third"
$array[2][2] = "third value"
For $i = 0 to UBound ( $array, $UBOUND_ROWS ) - 1 Step 1
    $array[$i][0] = GUICtrlCreateListViewItem ( $array[$i][1] & "|" & $array[$i][2], $listview )
Next

The [$i][0] part of the array will get the ID of the LW item. 

 

Additionally, i would add an extra listview column, which would hold a unique number.

with $array[3][4] 

and  

$array[$i][3]=$i

$array[$i][0] = GUICtrlCreateListViewItem ( $array[$i][3] & "|" & $array[$i][1] & "|" & $array[$i][2], $listview )

(and set the 1st column width to 0, so that the number is not shown)

In this way, you can always check the array with the item number, in case you want to sort or move the items around.

 

Edited by Dan_555

Some of my script sourcecode

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