ReportViewer control loading indicator?

三世轮回 提交于 2019-12-03 04:38:37

问题


Is it possible to change the image (the green spinning thing) of the ReportViewer control?

At the moment I am hiding it and overlapping a progress bar (this is WinForms not the ASP Control)... Seems a bit long winded?

Thanks :)


回答1:


Well, you gave me a challenge with this one my friend. But I figured out how to do this. Here is the code that I used to pull this off:

 Private Sub CustomizeRV(ByVal ctrl As Control)
    For Each c As Control In ctrl.Controls

      If TypeOf c Is PictureBox Then
        Dim pb As PictureBox = DirectCast(c, PictureBox)
        pb.Image = YOURNEWIMAGEHERE
      End If

      If c.HasChildren Then
        CustomizeRV(c)
      End If
    Next
  End Sub

Call this function during your form load event, and it will reconfigure the loading image to whatever you specify (pass the function the ReportViewer control). The function is called recursively until the picturebox is found. There is only one picturebox in the ReportViewer control, so you don't have to worry about finding that specific one.




回答2:


Thanks again to Jon for the original VB.NET code... Here is his answer in C#...

private void CustomizeReportViewer(Control reportViewer)
{
    foreach (Control c in reportViewer.Controls)
    {
        if (c.GetType() == typeof(PictureBox))
        {
            (c as PictureBox).ImageLocation = "C:\\Loading.gif";
            return;
        }

        if (c.HasChildren)
            CustomizeReportViewer(c);
    }
}



回答3:


For those bummed that this is for WinForms and not ASP.NET, this is the same solution for web:

Private Sub CustomizeRV(ByVal ctrl As Control)
    For Each c As Control In ctrl.Controls
        If String.Compare(c.ID, "AsyncWait")=0 Then
            DirectCast(c.Controls(0).Controls(0), Image).ImageUrl = ResolveUrl("~/images/PleaseWait.gif")
        End If

        If c.HasControls Then CustomizeRV(c)

    Next

End Sub



回答4:


Thanks a ton for sharing this question.Just converted the above vb.net code to c#.net and changed the image backaground color.

private void CustomizeRV(Control ReportViewCntr)
{
    foreach (Control c in ReportViewCntr.Controls)
       {            
          if ((string.Compare(c.ID, "AsyncWait") == 0))
          {   
            Image i = (Image)c.Controls[0].Controls[0];
            i.ImageUrl = ResolveUrl("~/Images/loading.gif");
            //i.BackColor = System.Drawing.Color.Gray; 
            i.BackColor = System.Drawing.ColorTranslator.FromHtml("#e6e6e6");
           }
          if (c.HasControls())
          {
            CustomizeRV(c);
        }
    }
}



回答5:


Thanks for the code sample to replace the image control in the AsyncWait. This was working absolutely fine till I upgrade my report viewer control to the latest version i.e. version 15.0.0.0.

After the upgrade the control at the position "c.Controls[0].Controls[0]" as in the code sample from @Pratik is no more an image control. Hence, it throws an error saying cannot convert LiteralControl to image.

I tried using above code with some minor edits as below:

 protected void CustomizeRV(Control ReportViewCntr)
    {
        foreach (Control c in ReportViewCntr.Controls)
        {
            if ((string.Compare(c.ID, "AsyncWait") == 0))
            {
                c.Controls[0].Controls.RemoveAt(0);                    
                Image i = new Image();
                i.ImageUrl = ResolveUrl("~/images/loading.gif");
                //i.BackColor = System.Drawing.Color.Gray; 
                i.BackColor = System.Drawing.ColorTranslator.FromHtml("#e6e6e6");
                c.Controls[0].Controls.AddAt(0, i);
            }
            if (c.HasControls())
            {
                CustomizeRV(c);
            }
        }
    }

However, it didn't work as expected.

Is there any other way we can replace the new literal control with the gif image?



来源:https://stackoverflow.com/questions/919895/reportviewer-control-loading-indicator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!