ReportViewer control loading indicator?

2019-03-09 05: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 :)

5条回答
何必那么认真
2楼-- · 2019-03-09 06:00

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楼-- · 2019-03-09 06:03

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楼-- · 2019-03-09 06:05

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?

查看更多
我命由我不由天
5楼-- · 2019-03-09 06:09

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);
        }
    }
}
查看更多
小情绪 Triste *
6楼-- · 2019-03-09 06:17

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.

查看更多
登录 后发表回答