Solved

assigning property to multiple controls

Posted on 2014-01-22
17
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 63

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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 28

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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