Solved

assigning property to multiple controls

Posted on 2014-01-22
17
170 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now