This is supposed to show the name, favorite color, and favorite number.
The XML and VBS files follow:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wescriptui>
<options>
<languageorder>
WE,OS,en-us
</languageorder>
</options>
<language id="en-us">
<dialog id="MyDialog1">
Dialog ListView
<group>
<group orientation="vertical">
<listview id="listview1" view="report">
<listviewcolumn>
Name
</listviewcolumn>
<listviewcolumn>
Favorite Color
</listviewcolumn>
<listviewcolumn>
Favorite Number
</listviewcolumn>
</listview>
</group>
<group>
<button id="btn_ok" system="ok" default="yes" widthclass="btn">
OK
</button>
<button id="btn_cancel" system="cancel" widthclass="btn" width="+10">
Close
</button>
</group>
</group>
</dialog>
</language>
</wescriptui>
Option Explicit
' We'll assume we have a list view whose ID is "listview1" which
contains no items by default
Dim isVisible : isVisible = 0
Dim Mark
Dim MyHotkey : Set MyHotkey =
Keyboard.RegisterHotkey("Control-Alt-Shift-I", "LaunchDialog")
Sub LaunchDialog()
If isVisible = 0 Then
Queue "DisplayDialog"
End If
End Sub
Sub DisplayDialog()
Dialog "DialogListViewFromScript.xml", "MyDialog1", "DialogEventHandler"
End Sub
Function DialogEventHandler(dObj, dEvent, dId, dControl)
DialogEventHandler = False
' Now we'll add items to the list view
If Mark < 1 Then
Dim NewLvItem
Set newLVItem = dObj.Control("listview1").NewItem
newLVItem.Text = "Aaron" & " " & dObj.Control("listview1").Text(1) & " "
& dObj.Control("listview1").Text(2)
newLVItem.Insert dObj.Control("listview1").Items.Count+1
newLVItem.Text(1) = "Obsidian Blue"
newLVItem.Text(2) = "42"
Dim NewLvItem2
Set newLVItem2 = dObj.Control("listview1").NewItem
newLVItem2.Text = "Jeff" & " " & dObj.Control("listview1").Text(1) & " "
& dObj.Control("listview1").Text(2)
newLVItem2.Insert dObj.Control("listview1").Items.Count+1
newLVItem2.Text(1) = "Red"
newLVItem2.Text(2) = "97"
Dim NewLvItem3
Set newLVItem3 = dObj.Control("listview1").NewItem
newLVItem3.Text = "Doug" & " " & dObj.Control("listview1").Text(5) & " "
& dObj.Control("listview1").Text(6)
newLVItem3.Insert dObj.Control("listview1").Items.Count+1
newLVItem.Text(1) = "Orange"
newLVItem.Text(2) = "256"
Mark = Mark + 1
End If
' The list view items would be read as "Aaron, Favorite Color Obsidian
Blue, Favorite Number 42."
Select Case dId
Case "btn_ok"
If dEvent = buttonClicked Then
SpeakResult dObj, dEvent, dId, dControl
DialogEventHandler = True
Exit Function
End If
Case "btn_cancel"
If dEvent = buttonClicked Then
Speak "close"
Sleep 200
isVisible = 0
dObj.Close
DialogEventHandler = True
Exit Function
End If
Case Else
If dEvent = dialogCreated Then
isVisible = 1
DialogEventHandler = True
Exit Function
End If
End Select
End Function
Sub SpeakResult(dObj, dEvent, dId, dControl)
Dim textToSpeak
' for just first column text
' TextToSpeak = dObj.Control("listview1").Text
' for entire row
TextToSpeak = dObj.Control("listview1").Text & " " &
dObj.Control("listview1").Text(1) & " " &
dObj.Control("listview1").Text(2)
Speak "You have chosen " & textToSpeak
End Sub
From: Chip Orange [mailto:[email protected]]
Sent: Friday, October 29, 2010 6:31 AM
To: [email protected]
Subject: RE: adding new items to a listview
Hi Jeff,
Not that I blame you, the documentation for these two topics (listview
and listviewitem) really could use some reworking for clarity's sake.
however, your lines like:
newLVItem.Text = "Aaron" & " " & dObj.Control("listview1").Text(1) & " "
& dObj.Control("listview1").Text(2)
don't seem to mean anything to me; I mean, the portion beyond the
string of "Aaron" that is.
maybe if you said what the listview should look like it would be clearer
to me?
thanks.
Chip
________________________________
From: Jeff Weiss [mailto:[email protected]]
Sent: Thursday, October 28, 2010 11:56 AM
To: [email protected]
Subject: adding new items to a listview
I am trying to figure out how to add additional items to a listview.
I want to add the items in my .vbs file.
What's wrong with these to items? I am not sure how to increment to the
next items:
If Mark < 1 Then
Dim NewLvItem
Set newLVItem = dObj.Control("listview1").NewItem
newLVItem.Text = "Aaron" & " " & dObj.Control("listview1").Text(1) & " "
& dObj.Control("listview1").Text(2)
newLVItem.Insert dObj.Control("listview1").Items.Count + 1
newLVItem.Text(1) = "Obsidian Blue"
newLVItem.Text(2) = "42"
' here's the second item I am trying to add:
Dim NewLvItem2
Set newLVItem2 = dObj.Control("listview1").NewItem
newLVItem2.Text = "Jeff" & " " & dObj.Control("listview1").Text(1) & " "
& dObj.Control("listview1").Text(2)
newLVItem2.Insert dObj.Control("listview1").Items.Count + 1
newLVItem2.Text(1) = "Red"
newLVItem2.Text(2) = "97"
Mark = Mark + 1
End if
Any help appreciated.
Jeff Weiss