Como ocultar os botões de exportar e salvar da barra do Toolbar (Ribbon) do controle ASPxRibbon do DevExpress.
Vamos lá...
Crie uma página .aspx e adicione o controle DocumentViewer
<dx:ASPxDocumentViewer ID="ASPxDocumentViewer1" runat="server" ToolbarMode="ExternalRibbon" AssociatedRibbonID="ASPxRibbon1">
</dx:ASPxDocumentViewer>
Modifique o atributo ToolbarMode para ExternalRibbon e defina o nome do controle Ribbon que será associado ao DocumentViewer, propriedade AssociatedRibbonID, como destacado no código acima.
Código do controle Ribbon usado pelo DocumentViewer:
<dx:ASPxRibbon ID="ASPxRibbon1" runat="server" EnableTheming="True" OnInit="ASPxRibbon1_Init">
<Tabs>
<cc1:DocumentViewerHomeRibbonTab>
<Groups>
<cc1:DocumentViewerPrintRibbonGroup>
<Items>
<dx:DocumentViewerPrintReportRibbonCommand>
</dx:DocumentViewerPrintReportRibbonCommand>
<dx:DocumentViewerPrintPageRibbonCommand>
</dx:DocumentViewerPrintPageRibbonCommand>
</Items>
</cc1:DocumentViewerPrintRibbonGroup>
<cc1:DocumentViewerExportRibbonGroup>
<Items>
<dx:DocumentViewerSaveToDiskDropDownRibbonCommand>
<Items>
<dx:RibbonPdfFormatCommand>
</dx:RibbonPdfFormatCommand>
<dx:RibbonXlsFormatCommand>
</dx:RibbonXlsFormatCommand>
<dx:RibbonXlsxFormatCommand>
</dx:RibbonXlsxFormatCommand>
<dx:RibbonRtfFormatCommand>
</dx:RibbonRtfFormatCommand>
<dx:RibbonMhtFormatCommand>
</dx:RibbonMhtFormatCommand>
<dx:RibbonHtmlFormatCommand>
</dx:RibbonHtmlFormatCommand>
<dx:RibbonTextFormatCommand>
</dx:RibbonTextFormatCommand>
<dx:RibbonCsvFormatCommand>
</dx:RibbonCsvFormatCommand>
<dx:RibbonPngFormatCommand>
</dx:RibbonPngFormatCommand>
</Items>
</dx:DocumentViewerSaveToDiskDropDownRibbonCommand>
<dx:DocumentViewerSaveToWindowDropDownRibbonCommand>
<Items>
<dx:RibbonPdfFormatCommand>
</dx:RibbonPdfFormatCommand>
<dx:RibbonXlsFormatCommand>
</dx:RibbonXlsFormatCommand>
<dx:RibbonXlsxFormatCommand>
</dx:RibbonXlsxFormatCommand>
<dx:RibbonRtfFormatCommand>
</dx:RibbonRtfFormatCommand>
<dx:RibbonMhtFormatCommand>
</dx:RibbonMhtFormatCommand>
<dx:RibbonHtmlFormatCommand>
</dx:RibbonHtmlFormatCommand>
<dx:RibbonTextFormatCommand>
</dx:RibbonTextFormatCommand>
<dx:RibbonCsvFormatCommand>
</dx:RibbonCsvFormatCommand>
<dx:RibbonPngFormatCommand>
</dx:RibbonPngFormatCommand>
</Items>
</dx:DocumentViewerSaveToWindowDropDownRibbonCommand>
</Items>
</cc1:DocumentViewerExportRibbonGroup>
<cc1:DocumentViewerNavigationRibbonGroup>
<Items>
<dx:DocumentViewerFirstPageRibbonCommand>
</dx:DocumentViewerFirstPageRibbonCommand>
<dx:DocumentViewerPreviousPageRibbonCommand>
</dx:DocumentViewerPreviousPageRibbonCommand>
<dx:DocumentViewerPageNumbersTemplateRibbonCommand>
<Template>
<dx:DocumentViewerRibbonCurrentPageLabel runat="server">
</dx:DocumentViewerRibbonCurrentPageLabel>
<dx:DocumentViewerRibbonPagesComboBox runat="server">
</dx:DocumentViewerRibbonPagesComboBox>
<dx:DocumentViewerRibbonPageCountLabel runat="server">
</dx:DocumentViewerRibbonPageCountLabel>
</Template>
</dx:DocumentViewerPageNumbersTemplateRibbonCommand>
<dx:DocumentViewerNextPageRibbonCommand>
</dx:DocumentViewerNextPageRibbonCommand>
<dx:DocumentViewerLastPageRibbonCommand>
</dx:DocumentViewerLastPageRibbonCommand>
</Items>
</cc1:DocumentViewerNavigationRibbonGroup>
<cc1:DocumentViewerReportRibbonGroup>
<Items>
<dx:DocumentViewerSearchRibbonCommand>
</dx:DocumentViewerSearchRibbonCommand>
<dx:DocumentViewerParametersPanelToggleCommand>
</dx:DocumentViewerParametersPanelToggleCommand>
<dx:DocumentViewerDocumentMapToggleCommand>
</dx:DocumentViewerDocumentMapToggleCommand>
</Items>
</cc1:DocumentViewerReportRibbonGroup>
</Groups>
</cc1:DocumentViewerHomeRibbonTab>
</Tabs>
</dx:ASPxRibbon>
Código C#
Método do evento OnInit="ASPxRibbon1_Init":
///Evento do controle Ribbon
protected void ASPxRibbon1_Init(object sender, EventArgs e)
{
List<Formato_Arquivo_Grid_BD> oExtensoes = null;
using (DB_Portal_Transparencia oBD = new DB_Portal_Transparencia())
{
oExtensoes = SG_Configuracao_NG.Formato_Arquivo.Pesquisar_Grid(oBD, new Formato_Arquivo_BD());
}
if(oExtensoes!=null && oExtensoes.Count > 0)
{
foreach (RibbonTab tab in ASPxRibbon1.Tabs)
{
RibbonGroup reportGroup = tab.Groups[1];
if (reportGroup == null)
continue;
RibbonItemBase reportGroup2 = reportGroup.Items[1];
foreach (var group2 in reportGroup2.Collection)
{
if (group2 is DocumentViewerSaveToDiskDropDownRibbonCommand)
{
DevExpress.XtraReports.Web.DocumentViewerSaveToDiskDropDownRibbonCommand DocumentViewerSaveToDiskDropDownRibbonCommand =
group2 as DevExpress.XtraReports.Web.DocumentViewerSaveToDiskDropDownRibbonCommand;
foreach (var item in DocumentViewerSaveToDiskDropDownRibbonCommand.Items)
{
Definir_Visibilidade(item as DocumentViewerRibbonDropDownButtonItemBase, oExtensoes);
}
}
else if (group2 is DocumentViewerSaveToWindowDropDownRibbonCommand)
{
DevExpress.XtraReports.Web.DocumentViewerSaveToWindowDropDownRibbonCommand DocumentViewerSaveToWindowDropDownRibbonCommand =
group2 as DevExpress.XtraReports.Web.DocumentViewerSaveToWindowDropDownRibbonCommand;
foreach (var item in DocumentViewerSaveToWindowDropDownRibbonCommand.Items)
{
Definir_Visibilidade(item as DocumentViewerRibbonDropDownButtonItemBase, oExtensoes);
}
}
}
}
//var showParametersPanelCommand = (RibbonToggleButtonItem)reportGroup.Items.FindByName("ShowParametersPanelToggleCommand");
//var showDocumentMapCommand = (RibbonToggleButtonItem)reportGroup.Items.FindByName("ShowDocumentMapToggleCommand");
}
}
///método que consulta a lista do banco e define a visibilidade do botão de exportação.
private DocumentViewerRibbonDropDownButtonItemBase Definir_Visibilidade(DocumentViewerRibbonDropDownButtonItemBase pItem, List<Formato_Arquivo_Grid_BD> pExtensoes)
{
DocumentViewerRibbonDropDownButtonItemBase obj = null;
switch (pItem.GetType().Name)
{
case "RibbonPdfFormatCommand":
obj = pItem as RibbonPdfFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "PDF" && c.Exibir == true);
break;
case "RibbonXlsFormatCommand":
obj = pItem as RibbonXlsFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "XLS" && c.Exibir == true);
break;
case "RibbonXlsxFormatCommand":
obj = pItem as RibbonXlsxFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "XLSX" && c.Exibir == true);
break;
case "RibbonRtfFormatCommand":
obj = pItem as RibbonRtfFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "RTF" && c.Exibir == true);
break;
case "RibbonMhtFormatCommand":
obj = pItem as RibbonMhtFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "MHT" && c.Exibir == true);
break;
case "RibbonHtmlFormatCommand":
obj = pItem as RibbonHtmlFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "HTML" && c.Exibir == true);
break;
case "RibbonTextFormatCommand":
obj = pItem as RibbonTextFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "TEXT" && c.Exibir == true);
break;
case "RibbonCsvFormatCommand":
obj = pItem as RibbonCsvFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "CSV" && c.Exibir == true);
break;
case "RibbonPngFormatCommand":
obj = pItem as RibbonPngFormatCommand;
obj.Visible = pExtensoes.Exists(c => c.Sigla.ToUpper() == "IMAGE" && c.Exibir == true);
break;
default:
break;
}
return obj;
}
Comentários