2008-09-22 7 views
7

누구든지 ReportViewer 도구 모음의 WinForms 버전 용 도구 모음을 수정하는 방법에 대한 아이디어가 있습니까? 즉, 일부 단추와 varius를 제거하고 싶지만 거기에있는 도구 모음을 수정하는 대신 새로운 도구 모음을 만드는 것이 솔루션처럼 보입니다.ReportViewer - 툴바를 수정 하시겠습니까?

처럼, 나는 엑셀로 내보내기를 제거했고, 이런 식으로했다 :

// Disable excel export 
    foreach (RenderingExtension extension in lr.ListRenderingExtensions()) { 
    if (extension.Name == "Excel") { 
     //extension.Visible = false; // Property is readonly... 
     FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); 
     fi.SetValue(extension, false); 
    } 
    } 

, 가능한 방법은 제어를 반복했다 당신이 toolbarbuttons을 제거하기 위해 나 .. 을 요구하는 경우 비트 trickysh 배열을 ReportViewer 내부에 배치하고 단추의 Visible 속성을 숨기도록 변경하면 항상 재설정되므로 좋은 방법은 아닙니다.

MS는 언제 새 버전 btw를 제공합니까?

답변

3

보고 싶은 버튼을 설정하는 데는 많은 특성이 있습니다.

예를 들어 ShowBackButton, ShowExportButton, ShowFindControls 등입니다. help에서 확인하십시오. 모두 "표시"로 시작하십시오.

하지만 맞습니다. 새 버튼을 추가 할 수 없습니다. 이렇게하려면 자신의 도구 모음을 만들어야합니다.

새로운 버전의 의미는? 이미 2008 SP1 버전이 있습니다.

0

일반적으로 수정하려는 경우 사용자 고유의 도구 모음을 만드는 것으로 가정합니다. 단추 제거를위한 해결책은 필요한 경우에만 작동하지만 원하는 항목을 추가하려면 글 머리 기호를 물고 대체품을 작성해야합니다.

7

Yeap. 당신은 조금 까다로운 방식으로 그렇게 할 수 있습니다. 확대/축소 보고서에 더 많은 축척 요인을 추가하는 작업이있었습니다.

ToolStrip toolStrip = (ToolStrip)reportViewer.Controls.Find("toolStrip1", true)[0] 

추가 새 항목 :

private readonly string[] ZOOM_VALUES = { "25%", "50%", "75%", "100%", "110%", "120%", "125%", "130%", "140%", "150%", "175%", "200%", "300%", "400%", "500%" }; 
    private readonly int DEFAULT_ZOOM = 3; 
    //-- 

    public ucReportViewer() 
    { 
     InitializeComponent(); 
     this.reportViewer1.ProcessingMode = ProcessingMode.Local; 

     setScaleFactor(ZOOM_VALUES[DEFAULT_ZOOM]); 

     Control[] tb = reportViewer1.Controls.Find("ReportToolBar", true); 

     ToolStrip ts; 
     if (tb != null && tb.Length > 0 && tb[0].Controls.Count > 0 && (ts = tb[0].Controls[0] as ToolStrip) != null) 
     { 
      //here we go if our trick works (tested at .NET Framework 2.0.50727 SP1) 
      ToolStripComboBox tscb = new ToolStripComboBox(); 
      tscb.DropDownStyle = ComboBoxStyle.DropDownList; 

      tscb.Items.AddRange(ZOOM_VALUES);     
      tscb.SelectedIndex = 3; //100% 

      tscb.SelectedIndexChanged += new EventHandler(toolStripZoomPercent_Click); 

      ts.Items.Add(tscb); 
     } 
     else 
     {     
      //if there is some problems - just use context menu 
      ContextMenuStrip cmZoomMenu = new ContextMenuStrip(); 

      for (int i = 0; i < ZOOM_VALUES.Length; i++) 
      { 
       ToolStripMenuItem tsmi = new ToolStripMenuItem(ZOOM_VALUES[i]); 

       tsmi.Checked = (i == DEFAULT_ZOOM); 
       //tsmi.Tag = (IntPtr)cmZoomMenu; 
       tsmi.Click += new EventHandler(toolStripZoomPercent_Click); 

       cmZoomMenu.Items.Add(tsmi); 
      } 

      reportViewer1.ContextMenuStrip = cmZoomMenu; 
     }      
    } 

    private bool setScaleFactor(string value) 
    { 
     try 
     { 
      int percent = Convert.ToInt32(value.TrimEnd('%')); 

      reportViewer1.ZoomMode = ZoomMode.Percent; 
      reportViewer1.ZoomPercent = percent; 

      return true; 
     } 
     catch 
     { 
      return false; 
     } 
    } 


    private void toolStripZoomPercent_Click(object sender, EventArgs e) 
    { 
     ToolStripMenuItem tsmi = sender as ToolStripMenuItem; 
     ToolStripComboBox tscb = sender as ToolStripComboBox; 

     if (tscb != null && tscb.SelectedIndex > -1) 
     { 
      setScaleFactor(tscb.Items[tscb.SelectedIndex].ToString()); 
     } 
     else if (tsmi != null) 
     { 
      if (setScaleFactor(tsmi.Text)) 
      { 
       foreach (ToolStripItem tsi in tsmi.Owner.Items) 
       { 
        ToolStripMenuItem item = tsi as ToolStripMenuItem; 

        if (item != null && item.Checked) 
        { 
         item.Checked = false; 
        } 
       } 

       tsmi.Checked = true; 
      } 
      else 
      { 
       tsmi.Checked = false; 
      } 
     } 
    } 
+0

감사합니다! 당신은 과도한 줌 요인 때문에 내가 가지고있는 문제를 방금 해결했습니다! (특정 보고서의 500 %가 win32의 깊은 곳에서 예외를 일으키고 있었다 ...) – matao

5

는 ReportViewer 컨트롤에서 도구 모음을 가져 오기 : 나는 이런 식으로 한

toolStrip.Items.Add(...) 
3

또 다른 방법을 통해 런타임에 생성 된 HTML을 조작하는 것 자바 스크립트. 매우 우아하지는 않지만 생성 된 HTML을 완벽하게 제어 할 수 있습니다.

+0

나는 이것이 오래된 게시물이라는 것을 알고 있지만 어떻게 완료 될지 자세히 설명 할 수 있습니까? ReportViewer의 무작위적이고 비상식적 인 HTML과 씨름 해 왔던 문제를 해결할 수있는 것 같습니다. – firedrawndagger

+2

@firedrawndagger : 그것에 대해 멋진 점은 없습니다. 나는 이것을 위해 jQuery $ (document) .ready() 핸들러를 사용하고 거기에서 reportviewer html 바를 조작한다. .NET 4의 새로운 ReportViewer 구성 요소는 기본적으로 ajax (Iframe 없음)를 기반으로하므로 더 쉽게 만들 수 있습니다. 그러나 보고서가 Iframe 내부에 있더라도 jquery를 통해 보고서에 액세스하는 방법은 여전히 ​​있습니다. 내가 코드를 게시 할 수 없다는 점은 유감스럽게 생각합니다. (이해하기 쉽도록 표현하기에는 너무 번거롭지 만) 제대로 작동한다는 것을 확신 할 수 있습니다. –

+0

감사합니다. 불행히도 저는 여전히 .NET3.5와 iframe이 붙어 있습니다. 그러나 JQuery를 뒤범벅해서 어떻게 될지 생각해보십시오. – firedrawndagger

1

나는이 질문을 가지고 있었다. 나는 긴 넥타이로 대답을 찾았고, 내가 사용했던 kowledge의 주요 소스는이 웹 페가였다. 나는 모든 사람들에게 내가 그것을 할 수있게 해주는 코드를 추가해 주셔서 감사하고 싶다. 결과가있는 그림. 대신의 ReportViewer 클래스를 사용

, 새 클래스의 사용을 만들 필요가, 내 경우, 나는 그것을 ReportViewerPlus라는 이름과는 다음과 같이 진행됩니다

using Microsoft.Reporting.WinForms; 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace X 
{ 
    class ReportViewerPlus : ReportViewer 
    { 
     private Button boton { get; set; } 

     public ReportViewerPlus(Button but) { 
      this.boton = but; 
      testc(this.Controls[0]); 
     } 
     public ReportViewerPlus() 
     { 
     } 
     private void testc(Control item){ 
      if(item is ToolStrip) 
      {  
       ToolStripItemCollection tsic = ((ToolStrip)item).Items; 
       tsic.Insert(0, new ToolStripControlHost(boton));  
       return; 
      } 
      for (int i = 0; i < item.Controls.Count; i++) 
      {  
       testc(item.Controls[i]); 
      } 
     } 
    } 
} 

당신은 생성자에서 직접 버튼을 추가해야 디자이너의 단추를 구성 할 수 있습니다.

여기 사진은 완벽하지는 않지만 충분히 가야합니다 (안전한 링크는 맹세합니다.하지만 내 자신의 사진을 게시 할 수는 없으며 충분한 평판이 없습니다).이 클래스의 코드에서주의 깊게 보면

http://prntscr.com/5lfssj

, 당신은 더 많거나 어떻게 작동하는지 덜 볼 것 당신은 당신의 변경을하고 가능한 도구 모음의 다른 사이트를 구축 할 수 있도록 할 수있다.

과거에 도움을 주셔서 감사합니다. 많은 사람들에게 도움이 되었기를 바랍니다.

+0

안녕하세요 @Alex이 유용한 솔루션이지만 보고서를로드 한 후에 만 ​​기존 도구 모음 프린터 단추에서 사용할 수 있습니다. 보고서를 사용하도록 설정 한 후 버튼을 활성화하려면 어떻게해야합니까?이 이벤트는 어떤 용도로 사용됩니까? –

1

웹 ReportViewer V11 (rv로 표시)의 경우 아래 코드는 버튼을 추가합니다.

private void AddPrintBtn() 
    {   
     foreach (Control c in rv.Controls) 
     { 
      foreach (Control c1 in c.Controls) 
      { 
       foreach (Control c2 in c1.Controls) 
       { 
        foreach (Control c3 in c2.Controls) 
        { 
         if (c3.ToString() == "Microsoft.Reporting.WebForms.ToolbarControl") 
         { 
          foreach (Control c4 in c3.Controls) 
          { 
           if (c4.ToString() == "Microsoft.Reporting.WebForms.PageNavigationGroup") 
           { 
            var btn = new Button(); 
            btn.Text = "Criteria"; 
            btn.ID = "btnFlip"; 
            btn.OnClientClick = "$('#pnl').toggle();"; 
            c4.Controls.Add(btn); 
            return; 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
0

CustomizeReportToolStrip 메서드를 사용하여 보고서 뷰어 컨트롤을 수정할 수 있습니다. 이 예제에서는 WinForm의 페이지 레이아웃 버튼, 페이지 레이아웃 버튼을 제거합니다.

public CustOrderReportForm() { 
    InitializeComponent(); 
    CustomizeReport(this.reportViewer1); 
} 


private void CustomizeReport(Control reportControl, int recurCount = 0) { 
    Console.WriteLine("".PadLeft(recurCount + 1, '.') + reportControl.GetType() + ":" + reportControl.Name); 
    if (reportControl is Button) { 
    CustomizeReportButton((Button)reportControl, recurCount); 
    } 
    else if (reportControl is ToolStrip) { 
    CustomizeReportToolStrip((ToolStrip)reportControl, recurCount); 
    } 
    foreach (Control childControl in reportControl.Controls) { 
    CustomizeReport(childControl, recurCount + 1); 
    } 
} 

//------------------------------------------------------------- 


void CustomizeReportToolStrip(ToolStrip c, int recurCount) { 
    List<ToolStripItem> customized = new List<ToolStripItem>(); 
    foreach (ToolStripItem i in c.Items) { 
    if (CustomizeReportToolStripItem(i, recurCount + 1)) { 
     customized.Add(i); 
    } 
    } 
    foreach (var i in customized) c.Items.Remove(i); 
} 

//------------------------------------------------------------- 

void CustomizeReportButton(Button button, int recurCount) { 
} 

//------------------------------------------------------------- 

bool CustomizeReportToolStripItem(ToolStripItem i, int recurCount) { 
    Console.WriteLine("".PadLeft(recurCount + 1, '.') + i.GetType() + ":" + i.Name); 
    if (i.Name == "pageSetup") { 
    return true; 
    } 
    else if (i.Name == "printPreview") { 
    return true; 
    } 
    return false; ; 
}