Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to dynamically build a name 2

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I have create a list of choices in a list box. When I grab the selected item properties I want that to trigger showing a second list box while hiding all others. There will be a rather long list.

I want to remove all spaces from the selected item text and prefix it with lb.

An example of what I am trying to do is:

Code:
    Private Sub MainMenu_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainMenu.SelectedIndexChanged
        Dim mmSelectedText = "lb" + Replace(MainMenu.SelectedItem, " ", "") As String
        lbManagingArchiving.Visible = False
        lbConfiguringSupportforClientsandDevices.Visible = False

        mmSelectedText.Location = New Point(27, 205)
        mmSelectedText.Visible = True


    End Sub

I then get an error that Location is not valid for a string. How do I convert my text string into a list box name so I can set the properties on the list box?

Any assistance is greatly appreciated.

Alternatively I would love to be able to create an expanding list box if anyone can point me to how to do that.

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Check out this FAQ:

faq796-5698

Once you have the control's name, the code in the FAQ above should give you what you need.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Couple of things...

First, instead of a bunch of listboxes and hiding/showing one, why not have one listbox that you change the datasource for - depending on the selection in the first listbox. This would shorten your code a bunch and make management much easier.

If that is not an option, the second item is that you cannot DIRECTLY access a control like you are trying to do. In order to modify a control during runtime, you need to get the actual control and perform the work against that control. You can get the name of the control like you have done, but then will need to cast that into a listbox, finding the actual control on the page, and then set your properties against the control itself.

Something like (typed, not tested):

Code:
Dim mmSelectedText As String = "lb" + Replace(MainMenu.SelectedItem, " ", "")
Dim lbControl As Listbox = DirectCast(Form.FindControl(mmSelectedText) As ListBox) 'This line might not be correct but the idea is correct
        lbManagingArchiving.Visible = False
        lbConfiguringSupportforClientsandDevices.Visible = False

        lbControl .Location = New Point(27, 205)
        lbControl .Visible = True

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
C#.NET Programmer
 
Thanks guys, I greatly appreciate your feedback as it helps me to widen my skill set. I'm normally just a scripting guy but I dabble in a bit of VB.net on occasion.

I decided it would be a lot easier on myself to use a menu control which allows me to drill down on things.

My project is going to customize PowerShell commands for about 150 Microsoft Lync tasks and the built in expandable topic capabilities of the menu was what I was trying to recreate in the first place.

Regards,
Mark

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top