none
Hiding a Backgound Image in RDLC RRS feed

  • Question

  • Hello,

    I am trying to add a watermark "draft" to my report body which is hidden/visible depending upon a value in the row of a datasource. I embedded the image, created an expression for visibility- hidden property and sent the image to back.

    It works fine but when printing the background image overlaps the regular table data even though.   I then tried a background image which worked perfectly. Its position and display are exactly what I need. The problem with the background image is there is no property available to hide it conditionally.

    Is it possible to hide a background image which prints in my table dependent on a cell value in the detail line of the table?  I found the following info at:

    http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportviewer.backgroundimage(VS.80).aspx

    Dim instance As ReportViewer
    Dim value As Image

    value = instance.BackgroundImage

    instance.BackgroundImage = value

    but I'm still unsure if can hide the background image via code.

    Thanks in advance.


    Thursday, August 28, 2008 2:05 AM

Answers

  • You can use an expression to control whether the table has a background image based on your data.

    For the table's BackgroundImage, set it to embedded, and embed the image you want to use, in my case I named it "draftImage". Then for the value, set it to something like this

    =iif(First(Fields!IsDraft.Value) = "draft", "draftImage", "") 

    What this does is it grabs the IsDraft field out of your data (rename to whatever you have named it of course) and compares it to "draft", if they are equal, it sets the table's background image to "draftImage" (rename to whatever you named the image) or to none if they don't match.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by HarpDog Thursday, August 28, 2008 8:34 PM
    Thursday, August 28, 2008 7:01 PM

All replies

  • The problem with BackgroundImage is that it is defined at the Control level. It has nothing to do with the report, all Controls have this property. So when you go to print your report, the background image will be left out.

    How does the image you embedded and sent to the back overlap the table data? Is it the image interferes with the rendering of the table, making it hard to read?


    And for the record, you can toggle BackgroundImage programmatically. Something like this event handler on a button will do the trick:

            private void button1_Click(object sender, EventArgs e)  
            {  
                if (reportViewer1.BackgroundImage == null)  
                {  
                    reportViewer1.BackgroundImage = _bgImage;  
                }  
                else  
                {  
                    reportViewer1.BackgroundImage = null;  
                }  
     
                Invalidate();  
            } 

    Or in your case during the form's Load event you could check the value of that row in your datasource and set the background accordingly. But again, I don't think BackgroundImage is what you want here.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Edited by Matt E Greer Thursday, August 28, 2008 6:09 PM Fixed typo
    Thursday, August 28, 2008 6:08 PM
  • Also, for the record, the report Body has a BackgroundImage property. That may be more effective for your needs than adding an Image and sending it to the back.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, August 28, 2008 6:15 PM
  • Hi Matt,

    Thanks so much for your assitance.

    <Also, for the record, the report Body has a BackgroundImage property. That may be more effective for your needs ....

    I *am* using the BackgroundImage property of my table contain in the report body. The resulting image is perfectly displayed in the background on my table.

    Each row of data in my table has a value telling me if the image should be displayed (draft or final mode).  All rows (non-normalized) will contain the same value - "draft" or "final".

    The problem as I see it is that a tables's background image property does not have a visibility property associated with it, it is always displayed.

    If I add an image to my table and send it to back instead of using the table's BackgroundImage property, the resulting image overlays some of the table details and does not display as 'nicely'. I tried all sizing modes.

    Is it possible to hide a table's BackgroundImage depending on a the table data?

    Thursday, August 28, 2008 6:40 PM
  • You can use an expression to control whether the table has a background image based on your data.

    For the table's BackgroundImage, set it to embedded, and embed the image you want to use, in my case I named it "draftImage". Then for the value, set it to something like this

    =iif(First(Fields!IsDraft.Value) = "draft", "draftImage", "") 

    What this does is it grabs the IsDraft field out of your data (rename to whatever you have named it of course) and compares it to "draft", if they are equal, it sets the table's background image to "draftImage" (rename to whatever you named the image) or to none if they don't match.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by HarpDog Thursday, August 28, 2008 8:34 PM
    Thursday, August 28, 2008 7:01 PM
  • Hi Matt,

    THat was exactly what I needed, you are brilliant - thanks!.
    Thursday, August 28, 2008 8:34 PM