Solved

assigning property to multiple controls

Posted on 2014-01-22
17
172 Views
Last Modified: 2014-05-20
I setup a list box on my form, and if my query returns values, I want it to be visible, otherwise not.
This is working fine.
So I thought, I'll add my buttons into the logic, but instead of duplicating code and setting them true/false within my if/then logic, I figured I would wait until the end of the routine and set their Visible property to the value of the listbox's visible property.
Lo and behold, they did not appear.  Stepping through the code, even at the point the list box should be made visible, it's still showing that that value is False (yet the list box show - and the buttons do not).
Seemed like a logical approach to me...what am I missing?
0
Comment
Question by:sirbounty
17 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39800929
It is hard to say without seeing the code that implements the functionality. Can you post the pertinent  code please.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39801239
Eh, I've left the office, but from memory...

lstResults.Items.Clear
If results.count > 0 then
  For each sr as searchresult in results
    lstResults.Items.Add sr.properties("displayName")(0).tostring()
  Next
  lstResults.Visible=true
Else
  lstResults.Visible=false
End If

btnDelete.Visible=lstResults.Visible
btnEdit.Visible=lstResults.Visible

Open in new window

0
 
LVL 40
ID: 39801525
Post the real code when you will be back at the office. Code from memory is almost always different than the real code, and usually miss the simple error that makes the original stick.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 67

Author Comment

by:sirbounty
ID: 39801755
Essentially the same as I posted from memory... ;^)

lstResults.Items.Clear()
Using adEntry As New DirectoryEntry(strADPath)
  Using ds As New DirectorySearcher(adEntry, adFilter)
    Dim src As SearchResultCollection = ds.FindAll
    If src.Count > 0 Then
      For Each sr As SearchResult In src
        'irrelevant code
      Next
      lstResults.Visible = True 'placing a break here and examining the value results in False, tho it IS shown
    Else
      lstResults.Visible = False
    End If
    btnEdit.Visible = lstResults.Visible
    btnDelete.Visible = lstResults.Visible
  End Using
End Using

Open in new window

0
 
LVL 67

Author Comment

by:sirbounty
ID: 39801762
Even tried placing a watch on it - never hits, but the listbox is displayed...really weird.
0
 
LVL 40
ID: 39801809
Strange one indeed. But code that seems irrelevant sometimes hides the problem.

Have you tried setting the buttons with btnEdit.Visible=(src.Count > 0)
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39801924
I've tried doubling the code anyway and setting the buttons to explicitly True - no joy. :(
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 0 total points
ID: 39803254
I ended up creating a boolean variable, and just set the controls to that value at the end.
Even though stepping through it, the value still shows False, the controls are visible.
Would still like to figure this out if anyone has any ideas...
0
 
LVL 40
ID: 39804272
Is it possible that you have something in the VisibleChanged event of the controls.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39804337
No, I don't. :(
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 126 total points
ID: 39804432
You might try setting the Enabled property instead of the Visible property.

If it works with Enabled, or if Visible is changed when you deal only with Enabled in the code that you present, then something somewhere is dealing with Visible.

If Enabled ends up showing the same behaviour as Visible, then the problem is not with the property itself. It could be another empty control, with no content or no border, that happens to hide the ListBox. Strange things like that happens you know, and often, when you have such a curious problem with code that seems so simple, it comes from one of these strange things.

Other than that, I will have to set my own Visible property to False. These sort of thing are almost impossible to diagnose at a distance, because we never have the complete picture. The problem is hidden somewhere in that whole picture.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 39804503
The controls are on a tab page...not sure that would be a culprit or not, but thought I'd mention it
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 126 total points
ID: 39804654
Could be the problem.

You could react to events in the TabPage that do stuff over what you expect.

Also, in design view it's not because a Control shows over a TabPage that it is part of that tab. It can simply be a standalone control that shows over the tab without being included in it. This can play tricks sometimes.

You can easily check this by using the Document Outline (Ctrl-Alt-T) by default. It shows you the hierarchy of containers and contained controls in the form.
0
 
LVL 27

Assisted Solution

by:Ark
Ark earned 62 total points
ID: 39805527
Just about looping through controls - you can use
Private ControlsAffected As Control() = {lstResults, btnDelete, btnEdit, moreControls}
'.....
Dim bVisible = src.Count > 0
For each c as control in ControlsAffected
   c.Visible = bVisible
Next

Open in new window

0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 62 total points
ID: 39806209
Controls on tab control do weird things when it comes to visibility and rendering as tab pages do not render themselves (and the controls on them) until needed.

One option is to move this code to tabcontrol.SelectedIndexChanged event and populate the controls there (but only if selected tab is the one containing this listbox and it is not populated already, use a boolean to track that).
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 0 total points
ID: 39806322
I'll post more details about it in a bit (when I get to work), but regardless, it's very strange that even though those values indicate they are false, the code works now, at least with the boolean controlling it and not the state of the listbox...
0
 
LVL 67

Author Closing Comment

by:sirbounty
ID: 40077096
Haven't found anything that explains why it doesn't work as it should, but at least I found a workaround.
Thanks for the help!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question