Hi
I have a number of reports displayed as gallery items in a PopupGalleryTool on a Office 2007 style ribbon. I would like to disable some reports based on whether the user has the necessary permissions to view the report.
Is it possible to disable a gallery item and if so how do I set the property?
Any help greatly appreciated.
Regards
James O'Doherty
Solutions and Database Architect
WINSQL Ltd
Hi James,
You can check the user's permissions in the BeforeToolDropdown event and disable the reports to which he or she does not have access. The following code can accomplish this:
private void ultraToolbarsManager1_BeforeToolDropdown(object sender, Infragistics.Win.UltraWinToolbars.BeforeToolDropdownEventArgs e){ if (e.Tool.Key == "PopupGalleryTool1") { PopupGalleryTool popup = e.Tool as PopupGalleryTool; foreach (ToolBase tool in popup.Tools) { bool bHasPermission = CheckPermisson(tool); tool.SharedProps.Enabled = bHasPermission; } }}
Hi Mike
Thank you - this is exactly what I was looking for. I have a follow-up question. When tool is disabled, the gallery item is not greyed out. Do I have to provide an appropriate image for this?
Solution and Database Architect
You can accomplish this by modifying my above code in the following way. This will remove any item from the list for which the user does not have proper permission:
private void ultraToolbarsManager1_BeforeToolDropdown(object sender, Infragistics.Win.UltraWinToolbars.BeforeToolDropdownEventArgs e){ if (e.Tool.Key == "PopupGalleryTool1") { PopupGalleryTool popup = e.Tool as PopupGalleryTool; List<GalleryToolItem> itemsToRemove = new List<GalleryToolItem>(); foreach (GalleryToolItem item in popup.Items) { if (!CheckPermisson(item)) itemsToRemove.Add(item); } foreach (GalleryToolItem item in itemsToRemove) { popup.Items.Remove(item); } }}
Please let me know if you have any further questions.
I believe this can be achieved. However, I will need to do a bit of research to determine the best way to accomplish it. I will look into it and provide you with more sample code as soon as I can. I am aiming to get this to you on Monday -- I will provide an update no later than Wednesday if it takes longer than expected.
I have tried to implement your code however the Tools collection of the PopupGalleryTool has no items. The items in the PopuGalleryTool are GalleryToolItem that are created using the following code
Dim galleryItems() As GalleryToolItem = {New GalleryToolItem("Cross Office Charges", "Cross Office Charges"), _ New GalleryToolItem("Top 10 Clients", "Top 10 Clients"), _ New GalleryToolItem("Staff Leave", "Staff leave"), _ New GalleryToolItem("Absence Analysis", "Absence Analysis"), _ New GalleryToolItem("Phone List", "Phone List"), _ New GalleryToolItem("Emergency Contacts", "Emergency Contacts"), _ New GalleryToolItem("Staff Addresses", "Staff Addresses"), _ New GalleryToolItem("Timesheet Analysis", "Timesheet Analysis"), _ New GalleryToolItem("Utilisation Analysis", "Utilisation Analysis"), _ New GalleryToolItem("Work Life Balance", "Work Life Balance")}
Dim reportGallery As PopupGalleryTool = toolbarsManager.Tools("reportGalleryTool")
' Add the GalleryToolItems to the PopupGalleryTool reportGallery.Items.AddRange(galleryItems)
How do I access the SharedProps for a gallery tool item?
James