I have created a webToolbar as a control Container that I want to add to a number of web pages. I have a number of issues that i cant seems to see how to do. I have named the buttons on the toolbar for example: btnBack, btnHome, btnHelp etc.
On one page I want to hide the btnBack button but I cant seem to do “myToolbar.btnBack.Visible = false” so not sure how to make this work.
If I remove buttons (as per point 1) then how do I know which button is pressed in the ButtonAction event because the index will have changed so how do I map an index number to the buttons name?
In ButtonAction event…
Select Case Item.Name
Case “Button Name 1”
Case “ButtonName 2”
Thanks Mark that has got me a bit further but I am still stuck on point 1 as to how you hide buttons your dont want on certain pages etc.
The docs appear to be a little misleading as they say:
Toolbar1.Button1.caption = "Hello"
But in the IDE the “Button1” does not autocomplete or come up when you press tab to see what is available.
In my project the toolbar is called “topToolbar” and I have a back button called “btnBack” so I have tried the following but this gives an error saying “this item does not exist”
topToolbar.btnBack.visible = false
If it is possible to get the index number for a name e.g. “btnBack” then I could use the removeItem and pass the index number to the method but I cant even see how I can find the index number for a button name.
Make sure you use the name of the toolbar object that you added to the page, not the name of the original toolbar class/object.
Sorry a typo on my part. In the container shown event on the web page I have the following line of code which does not compile, where me is the container and topToolbar is the toolbar and btnBack is the name of the button I want to hide:
me.topToolbar.btnBack.visible = false
I have uploaded a simple test to show it not working. If you look at the container control event in the web page you will see where I am trying to change the visible and it wont compile. Also if you try and type “me.topToolbar.btn” it doesnt autocomplete etc.
the toolbar is composed of WebToolbarItem that you refers with ItemWithName or ItemAtIndex.
When referring to an element of the toolbar you must cast the element itself to the correct type i.e. WebToolbarButton(topToolbar.ItemWithName(“btnBack”)).
The WebToolbarButton has no Visible property.
Thanks Maurizio. so is the opinion that you cannot remove a button with its name? If that is the case then how do you remove buttons using the removeitem as every time you remove something the items after it all move as well and how do you know the name of the button at the index position to know if it is the one you want to remove?
If you only want to hide the first item and not remove it (which is possible from 2014R2), move the toolbar to the left. Something like -60 for toolbar.left will hide the first item, and back to 0 will show it again.
The RemoveItem method does not seem to take the name :
Nice idea with moving but I have a toolbar with about 12 icons and depending on the page I want to hide a number of them (different on different pages). The removeitem uses an index but I cant see how you get the name of the item at the index position as you loop through them. If I can make that work then i could start with the last item and work down and then use the removeitem which then wont mess up the order. Very messy but it would work, would be much better if you could just use a visible on the item name itself.
Ok, I have finally got it to work with everyone’s help on this post it suddenly made some sort of sense so below is a copy of what I did. Please note that the “me” is referring to the shown even for the container control where I have the toolbar. Thanks everyone for the assistance.
[code] Dim button As WebToolbarButton
For i As Integer = Me.topToolbar.ItemCount-1 To 0 step -1
If Me.topToolbar.ItemAtIndex(i) IsA WebToolbarButton Then
button = WebToolbarButton(Me.topToolbar.ItemAtIndex(i))
select case button.Name
case "btnBack", "btnSort", "btnRefresh"
instead of removing the item itself you can do:
- save the 3 properties caption, image and enabled in other vars
- set caption="" , image=nil , enabled=false
- restore the 3 properties when you need to show the item again.
Thats clever, I like that idea, will have a play with that later this evening. Thanks.
Instead of looping in the items array declare a WebToolbarButton as a property of the container and store in it a reference to the button.
mybackbutton = WebToolbarButton(Me.topToolbar.ItemWithName(“btnBack”))
You can use mybackbutton directly without rescan each time the toolbar itself when you need to manipulate the toolbar element.
I came across this thread looking around to find a way to hide-show a WebToolbarButton. Thanks to Nathan for starting this thread, and everyone for their suggestions. @Maurizio Rossi I found that particularly interesting and implemented that as a solution to a ToolBar
Here is a snippet of the code I use in my Web App
[code]Dim myUsersbutton As WebToolbarButton
myUsersbutton = WebToolbarButton(cloudToolbar.ItemWithName(“THE NAME OF THE WebToolbarButton”))
'— How to hide or show a ToolBar Item depending on their Privilege
'— This ‘Session.CurrentUser.Privilege’ is a db value assigned to users who have accounts
'— and is obtained when attempting to log in
'— Implement your own method to control Hide-Show
If Session.CurrentUser.Privilege = “WHATEVER PRIVILEGE VALUE YOU USE” Then
'— This Shows the WebToolbarButton
myUsersbutton.Icon = ‘THE PIC FOR THIS BUTTON YOU WANT TO SHOW’
myUsersbutton.Caption = “THE CAPTION FOR THIS BUTTON YOU WANT TO SHOW”
myUsersbutton.Enabled = True
'— Otherwise hide everything
myUsersbutton.Icon = Nil
myUsersbutton.Caption = “”
myUsersbutton.Enabled = False
This is fast, simple and demonstrates what @Maurizio Rossi described
Thanks again to everyone