Hi Chip,
I disabled the keyboard event to test it and as I had stated, the Index is
not available until the event is over for a ListView and focused obtained.
If a person wanted a dynamic index value on the fly when the event happens
it will not be there.
I think this is an important point for those who as Jeff wanted to, go up
and down the list and get the index value you have to wait until focus is on
that item. But since Jeff apparently only wanted the text than it is OK for him
but the Index is important for all other needs.
So if you just wanted the text of that item, yes it is gotten under the
control text value and you can get it during the event which I think Jeff
wanted.
So it depends on what you want or need in a dynamic situation.
As I stated, to get the Index in the ListView while moving up and down the
list you can look at the key event, set a timer delay and call a function, or
wait until you do something after focus is obtained as your example showed,
tabbing to a button after it is enabled by the event and clicking on it.
Just an important observation for those who use the ListView in the future.
I read your other email and I guess for event numbers I will have to search
through the Microsoft site and see where they hide the actual numbers for the
names.
Bruce
Sent: Thursday, January 16, 2014 7:53 PM
Subject: RE: listbox change
Bruce,
I don't quite understand your point, but I admit that I am not interested in
using key up and key down events, and I am sure it is not necessary to do so
in order to get index numbers from the listview. Perhaps things aren't
available while key processing is going on, that's not really documented by
GW.
Chip
-----Original Message-----
From: LB [mailto:[email protected]]
Sent: Thursday, January 16, 2014 5:42 PM
To: [email protected]
Subject: Re: listbox change
Hi Chip,
I just looked at that class and yes, class 31 shows an example which I
had discovered in my test but had not used in my app until Jeff had asked
the question.
Your example I just looked at shows a use of the event to assign buttons
there enable state and nothing else.
Also you mentioned the text part of the Listview which I mentioned does
work for you can get the text, but what about the Index number?
It does not give that part of the control, it flat out says there is no
object, at least not yet. For it appears that this part of the control does
not come out until you have released the key you pressed. the index comes
out when the item has focus and I suspect that does not happen until the
action is done.
The object model book states that some objects are not available and
that is one of them after trial and error and posting results to Jeff. Now
the difference is he is using a listbox not a listview and I have not tested
to see if the index number comes up while the event is happening.
Now, I also had added the focused event where when moving away from the
window and back, interestingly it gives that part of the control which gives
out the index number. so you will note in my lengthy example I do not go
into any key pressed mode, I go directly to the routine to get the index
number for it.
The reason why is that when this event is triggered the item has focus.
this event is only triggered when moving into the window of the control.
but in the changed event there is no object given beneath the control
level. It says it needs an object, either inside the event if nor in the
Queue call to the routine, in both cases the error is, "Needs an object!"
I just tested to see if the Items.Selected.Focused.Index works and "NO"
for this is doing the same thing, it first wants focus before giving up that
property.
What I am saying when attempting to use the Items part of the list view
there is no object given until focus is complete. In other words the control
collection has not been formed until focus is obtained.
So, in order to get the object I have to wait until the key is released,
or the key up event, in which the key modes are only given under
keyprossedUp event which makes sense for it means what it says.
So at the moment I set a flag to extract the data I need and call the
routine to give me that information when the key is released. This is
actually the same thing your example does in setting button flags and
enabling them. For in doing so you have to make another key action after
focus is done to get to that button.
You could test it and you would find the same problem, the items object
only under the listviewChanged event is not there, nor is the item object,
just the control properties and methods.
I probably have talked too much on this and one can get lost when
stating too much.
summary, under this event there has been no collection formed yet.
Bruce
Sent: Thursday, January 16, 2014 1:19 PM
Subject: RE: listbox change
Bruce,
I'm still confused as to what you're problem is.
Class # 31 shows how to deal with detecting when a listview selected item
has changed.
Chip
-----Original Message-----
From: LB [mailto:[email protected]]
Sent: Wednesday, January 15, 2014 7:50 AM
To: [email protected]
Subject: Re: listbox change
Hi Chip,
My mistake, I am playing with the ListView and it has less features than
the ListBox and tried to mention that. I also had no time to test it out and
that makes it more confusing.
For in the ListBox you have everything for setting and getting items but
no columns which I wanted at first but may not use in the future.
At least Jeff has an example he can use but I did try to stress that all
the features he needed did exist in the ListBox but not the ListView.
For when EventInfo is only given it defaults to the control and not it's
items in some case, for there is just no control for a selected item; it
says no object, and noticed it went to the control level instead.
Buttons are nice but as I had stated, the keydown event and keyup even
can be used to compensate for control loss by setting and resetting a flag.
Hopefully Jeff can get his app running using the example and yes, having
all the flags set for an app such as the Explicit is very important to
reduce debug time.
Bruce
Sent: Tuesday, January 14, 2014 8:11 PM
Subject: RE: listbox change
Hi Jeff,
I'm sorry to keep disagreeing with Bruce, but I did take your example, made
several corrections, and it works just as expected.
You have several places where your names in the vbs don't match the names in
the xml, and you have a variable (or two) which aren't initialized (I think
sButton was one of them). It might help if you added "option explicit" at
the top of the vbs.
Anyway, below is a modified version of your vbs example which speaks some
extra text each time the selected listbox item changes. First yu'll hear We
read the new listbox item, then you'll hear my modified example speak the
same line with some added text at the beginning so you can tell it apart
from what WE is speaking.
Aside from correcting variable names, all I did was to add a test for the
listboxSelectionChange event(and as Bruce pointed out), you do have to
initialize it to start with, so that it will work the very first time;
otherwise, it won't start working until the second time.
option explicit
Dialog "testlist.xml", "Dialoglistbox", "DialogEventHandler"
Function DialogEventHandler(dObj, dEvent, dId, dControl)
Dim Result : Result = ""
If dEvent = dialogCreated Then
dObj.Control("lst").Width = 800
BuildList dObj
End If
DialogEventHandler = False
Select Case dEvent
' Process dialog events
case ListboxSelectionChange
DialogEventHandler = True
queue "SaySelectedItem", dObj.control("lst").text
Case dialogCreated
DialogEventHandler = True
Case buttonClicked
If dId = "btnCancel" Then
dObj.Close
DialogEventHandler = True
End If
If dId = "BtnOk" Then
Result = dObj.Control("lst").Text
queue "SaySelectedItem", Result
DialogEventHandler = True
End If
End Select
End Function
Function BuildList(dObj)
dObj.Control("lst").Add "This is the first line in the listBox!"
dObj.Control("lst").Add "Here is the second line."
dObj.Control("lst").Add "Here is the third and longest line in the listbox!"
dObj.Control("lst").FocusedIndex = 1
End Function
Sub SaySelectedItem(Result)
Speak "The item you selected was " & VbCrLf & Result
End Sub
Hth,
Chip
-----Original Message-----
From: Jeff Weiss [mailto:[email protected]]
Sent: Tuesday, January 14, 2014 12:12 PM
To: [email protected]
Subject: Re: listbox change
I was unable to get any info while still in the list. I found another way
to do what I wanted.
I added an extra button, made it the default button with enter as its
shortcut, and by pressing enter while still in the list, I can get extra
information. That's not exactly what I wanted, but it's close.
Below is a .vbs and a .xml file showing a simple listbox with 2 buttons.
The files are nameed
DialogListBoxFromScript.vbs
DialogListBoxFromScript.xml
If anybody wants to try to add something to the select case section to
automatically speak additional information when you are just up or down
arrowing through the list, I would certainly appreciate knowing how to do
this.
thanks again,
Jeff Weiss
' DialogListBoxFromScript
Dim IsVisible : IsVisible = 0
Dim myHotkey : Set myHotkey =
Keyboard.RegisterHotkey("Alt-Control-Shift-I","LaunchDialog")
Sub LaunchDialog()
'This routine is called when the hotkey is pressed.
If isVisible = 0 Then
Queue "DisplayDialog"
End If
End Sub
Sub DisplayDialog()
Dialog "DialogListBoxFromScript.xml", "Dialoglistbox", "DialogEventHandler"
End Sub
Function DialogEventHandler(dObj, dEvent, dId, dControl)
Dim Result : Result = ""
dObj.Control("lst").Width = 800
If dEvent = dialogCreated Then
BuildList dObj, Result
End If
DialogEventHandler = False
Select Case dEvent
' Process dialog events
Case dialogCreated
DialogEventHandler = True
Case buttonClicked
sButton = dControl.Text
sButton = Replace(sButton, "&", "")
Speak sButton
If sButton = "Close" Then
dObj.Control("lst").Clear
dObj.Close
Exit Function
End If
If sButton = "Ok" Then
Result = dObj.Control("lst").Text
SaySelectedItem dObj, Result
Result = ""
Exit Function
End If
End Select
End Function
Function BuildList(dObj, Result)
dObj.Control("lst").Add "This is the first line in the listBox!"
dObj.Control("lst").Add "Here is the second line."
dObj.Control("lst").Add "Here is the third and longest line in the listbox!"
dObj.Control("lst").FocusedIndex = 1
End Function
Sub SaySelectedItem(dObj, Result)
Sleep 200
Speak " "
Speak "The item you selected was " & VbCrLf & Result
Sleep 1000
End Sub
' here is the .xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wescriptui>
<options>
<languageorder>
WE,OS,en-us
</languageorder>
</options>
<language id="en-us">
<dialog id="Dialoglistbox" modal="yes">
ListBox from Script
<group>
<group>
<static shortcut="l">
List
</static>
<listbox id="lst" sort = "no">
</listbox>
</group>
<group justify="center">
<button id="BtnOk" default="yes" widthclass="button" shortcut="Enter">
Ok
</button>
<button id="btnCancel" system="cancel" widthclass="button">
Close
</button>
</group>
</group>
</dialog>
</language>
</wescriptui>
From: Chip Orange [mailto:[email protected]]
Sent: Monday, January 13, 2014 12:21 PM
To: [email protected]
Subject: RE: listbox change
Jeff,
I don't see that you're initializing the variable Temp anywhere, and I also
don't see that you are setting the focusedIndex property of the listbox
anywhere (which is usually done when you add items to the listbox; you
usually set it to 1 when you add your listbox items).
Take out the line:
If fObj("lst").FocusedIndex <> Temp Then
And you should then hear something spoken each time your listbox item is
changed.
Chip
From: Jeff Weiss [mailto:[email protected]]
Sent: Sunday, January 12, 2014 10:33 PM
To: [email protected]
Subject: Re: listbox change
Thank you for all of the suggestions.
This is indeed my own xml listbox dialog and I can get the button to work
but not the listbox change to register where I can do something when it
changes.
The list works fine and displays 12 spelling words.
Here is the function:
Function DialogEventHandler3(fObj, fEvent, fId, fControl)
DialogEventHandler3 = False
Dim Result : Result = ""
fObj.Control("lst").Width = 200
If fEvent = dialogCreated Then
BuildList fObj, Result
End If
DialogEventHandler3 = False
Select Case fId
Case fId = "lst"
If fEvent = listboxSelectionChange Then
If fObj("lst").FocusedIndex <> Temp Then
Temp = fObj.Control("lst").FocusedIndex
Result = fObj.Control("lst").Text
Speak Result
Speak Temp
Speak "this is a test."
Result = ""
Exit Function
End If
End If
Case "button_MainMenu"
If fEvent = buttonClicked Then
Speak ""
Sleep 200
Speak "Returning to Main Menu"
Sleep 200
fObj.Control("lst").Clear
fObj.Close
DialogEventHandler3 = True
Exit Function
End If
Case Else
If fEvent = dialogCreated Then
DialogEventHandler3 = True
Exit Function
End If
End Select
End Function
I must be missing something here. Please let me know what I am missing
here.
thanks
Jeff Weiss
Jeff Weiss, M.Ed.
Director of Life Skills
Rehabilitation Teacher
World Services for the Blind
2811 Fair Park Blvd.
Little Rock, AR 72204
Email: [email protected]
www.wsblind.org
The mission of World Services for the Blind is empowering blind or visually
impaired adults in the United States and around the world to achieve
sustainable independence.
---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com
---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com