Jeff,

There are two problems with your script.

The first is you have it insert on the very first event sent to your Dialog callback (DialogEventHandler). The problem is the first event that comes through is to early to be playing with the listview. As a simple test I wrapped your "If Mark < 1 Then" if around another if that says:

If dEvent = dialogCreated Then

This way you only try and insert it when you get the dialogCreated event which means the dialog is there and the controls are on it but it hasn't been put to the screen yet. This is where you can safely play with the controls. My guess is your Mark stuff can go away as this was probably your way to do it just once...but dialogCreated only gets called once anyway.

The second problem is when you insert "Doug" you created newLVItem3 and you use this for the "Doug" part but the second and third columns you use newLVItem which actually changes the first rows entries leaving these columns empty in the Doug row.

So fix box of these and the world will be round for you <smile>.

Doug

On 11/1/2010 11:54 PM, Jeff Weiss wrote:
Well, Chip--I guess I did muddy the waters a bit.
I did figure out how to deal with the listview when all the items were in the xml file.
This is not what I asked about at first.
Sorry about that.
So, I still don't see why this script does not work.
Note: here is the script that attempts to add the 3 items from the .vbs file. It doesn't work! Only the names are displayed in the listview, and when trying to retrieve the colors and numbers, the subscripted items get the other names from the list.
Lines 27 through 46, and line 88 must not be correct.
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 : Mark = 0
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"
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"
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"
newLVItem3.Insert dObj.Control("listview1").Items.Count+1
newLVItem.Text(1) = "Orange"
newLVItem.Text(2) = "256"
Mark = Mark + 1
End If
' The first list view items should 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
Here is the xml:
<?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>

Reply via email to