Still having Focus issues

1 view
Skip to first unread message

XavRam

unread,
Sep 17, 2008, 4:51:54 PM9/17/08
to EEGUI
I have a list of labels that highlight (border changes color) when the
mouse moves over them. When I click on one of them, the border goes
back to the way it was before teh mouse was over it. If I mouse the
mouse over the other labels, the border chagnes color as
expected....but not if I go back to the label that I had clicked.
Only AFTER I click on another label does the first label become
"active" again.

XavRam

unread,
Sep 18, 2008, 4:54:07 PM9/18/08
to EEGUI
Bah, further issue with this...

The labels are mention are the children of a list box control. When I
click on one of these (mouse down event), I need the list box control
to clear out all the children. So...

private sub ClearAllChildren
Dim x As Integer
For x = Children.Count - 1 To 0 Step -1
Children.RemoveAt(x)
Next
end Sub

However, when I do this, the label I clicked on is still in the list,
in the spot that it was orgiinally. So, if there were 4 labels in the
list and I clicked on the 3rd, the 3rd one stays there while the 1st,
2nd, and 4th ones disappear.

After this clear, to check my sanity, I did a
Msgbox(ListBox.Children.Count) and got back 0.

If I click on the remaining label a 2nd time, THEN it disappears.

So the next thing I tried was to add a button somewhere on my form and
tie its click event to that ClearAllChildren Event. Wow, if I click
that button, then everything gets cleared off the list box control on
the first try.

There appears to be something going on with the refreshing of the list
box if a child in it was clicked. I thought it was a focus issue but
setting the Focus = False after clicking the item doesn't change the
behavior!

Help! If needed, I can send someone the actualy classes I'm using for
this.

Jared Mark

unread,
Sep 19, 2008, 12:08:39 AM9/19/08
to ee...@googlegroups.com
Part of the problem is that you can't change a list while enumerating
through it.

So for example:

For Each Child as guiControlBase in SomeControl.Children
SomeControl.RemoveChild(Child)
Next

Will not work, because when it hits the "next", the SomeControl.Children
list has been modified. This actually throws an exception, and I'll bet the
exception is being written to the EEGUI Debug log file...

There are two ways to work around this...

If you are wanting to remove just ONE child, based on something like a
TagID, you could do this:

For Each Child as guiControlBase in SomeControl.Children
If Child.TagID = MyParameter Then
SomeControl.RemoveChild(Child)
Exit For
End If
Next

This exits the For loop when a successful match is found... so you remove
from the list, but don't attempt to go farther THROUGH the list, thus
avoiding the problem.

Otherwise, you should do a While loop, and RemoveAt index 0 each time until
children.count = 0

While SomeControl.Children.Count > 0
SomeControl.RemoveChild(SomeControl.Children(0))
End While

This is not iterating through a collection... it's merely checking the
number of children in the list each time through. Thus, you can keep
removing form it until there are 0 children left. As long as there are
children left, it will remove the "first child in the list"...
No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.169 / Virus Database: 270.6.21/1677 - Release Date: 9/17/2008
5:07 PM

Jared Mark

unread,
Sep 19, 2008, 12:10:49 AM9/19/08
to ee...@googlegroups.com
By the way... I just modified EEGUI to do that last suggestion for
RemoveAllChildren.

I had it iterating through a loop, and even though I knew it would probably
cause problems, I never remembered to go back and fix it.

Expect a new DLL soon... too many changes pending for you guys to miss out
on for much longer. :)

XavRam

unread,
Sep 19, 2008, 11:52:24 AM9/19/08
to EEGUI
Damn, while you're explanation makes perfect sense, the solution still
doesn't work. I changed my ClearAllChildren to...

Public Sub ClearMessages()
While Children.Count > 0
Children.RemoveAt(0)
End While
End Sub

...and I get the exact same behavior. The label that I clicked on
that fired off this event is still there and only after clicking on it
a 2nd time does it disappear.

So if you implement this routine into the RemoveAllChildren, I still
think you'll have issues.
> Checked by AVG -http://www.avg.com
> Version: 8.0.169 / Virus Database: 270.6.21/1677 - Release Date: 9/17/2008
> 5:07 PM
>
> No virus found in this incoming message.
> Checked by AVG -http://www.avg.com
> Version: 8.0.169 / Virus Database: 270.6.21/1677 - Release Date: 9/17/2008
> 5:07 PM- Hide quoted text -
>
> - Show quoted text -

XavRam

unread,
Sep 19, 2008, 11:55:50 AM9/19/08
to EEGUI
Ha!!! Changed it again, to...

Public Sub ClearMessages()
While Children.Count > 0
RemoveChild(Children(0))
End While
End Sub

...and now it worked! Great!
> > - Show quoted text -- Hide quoted text -

Jared Mark

unread,
Sep 19, 2008, 2:47:31 PM9/19/08
to ee...@googlegroups.com
Yeah, you can't do RemoveAt, because it doesn't do the logic for child
removal...
Checked by AVG - http://www.avg.com
Version: 8.0.169 / Virus Database: 270.7.0/1680 - Release Date: 9/19/2008
8:25 AM

Reply all
Reply to author
Forward
0 new messages