none
how to show images in 1 row based on user selection. RRS feed

  • Question

  • Hello,

    I am using Report Viewer Control in VS2005. i want to show images on the report but display depends on user selection.

    Like this:  I have a winform where there is a combo box with options like
    1x1
    2x2
    3x3.

    So if user selects 1x1 then on the report i have to show  1 image in 1 page
    if 2x2 then 2 images in 1 row and in 1 page. so if there are 8 images then 2 images in 1 row on page1, 2 in 1row on page2 and so on.


    Got so far:  i have a Rectangle with list and image control on it.
                     i have  a datatable  with coloum storing image file address on the hard drive.
                     i can see the images on report but on 1 page and 1 below the other.


    How do i manage the display of images on user choice.


    Please help.




    Wednesday, November 7, 2007 4:37 PM

All replies

  • I've not done anything like this directly, but with my understanding of the ReportViewer, the way I'd attack this is to actually have three different reports all formatted etc based on each of the three selections.

     

    Then, after the user selects the combobox value, load one of the three reports based on their selection and etc.

     

     

    Wednesday, November 7, 2007 7:17 PM
  • Hello,


    are you saying create 3 sub reports. How will i get the user selection ..i mean how do i use it to dynamically select the sub reports..
    i will have to write some code..if yes then where exactly.


    Please help with this as its very important and much needed to me.
    Wednesday, November 7, 2007 7:22 PM
  • No, not seperate subreports, seperate reports.

     

    I'm not familiar with conditional formatting/etc, and don't want to even suggest that's possible. Perhaps someone else here might have an elegant solution based on subreports etc.

     

    If I were asked to solve your issue, I'd create three completely seperate reports, one for the 1x1 option (say, Report1x1.rdlc), one for the 2x2 option, and one for the 3x3 option.

     

    Based on the users' selection in the combobox, I'd branch my code into paths that load the desired report (Report1x1.rdlc), etc.

     

    Wednesday, November 7, 2007 7:29 PM
  • I think it probably *is* possible -- unless I'm missing something. What you are talking about looks like a classic "snaking columns" scenario...  I'm not saying that you shouldn't follow Eldelo's advice to use separate reports, just that it is possible to do it in one <g>.

     

    There are a couple of ways to do it that would involve kludging on the SQL side so that the images are each in a different column. I don't think that's the right way here. ***

     

    Basically: think of it like you're doing label layouts.  This is a good place for list regions rather than tables, although you could potentially do it with tables as well. 

     

    I think, you might want to think about something we have called a "sideways" report somewhere on these forums.  Here it is: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1884918&SiteID=1 -- read this thread and tell me what you think.

     

    In your case, you will have visibility expressions that are tuned to the layout option that the user picked.  You will have Visibility options that will point to different row numbers each, just like in the above thread, but each Visibility expression will also be sensitive to which layout option was picked rather than hardcoding the row number for each list the way I did it in that thread.

     

    *** If you *were* doing it this way  I have a rather convoluted problem-to-solve and solution described here that I think might also have some ideas germane to what you guys are talking about http://spacefold.com/lisa/post/Reporting-Convergences-Chapter-Multi-Detail-Bands%2c-SQL-Reporting-Services-Style.aspx.  It's not exactly the same, but here I'm using row visibility in a way that you could do as well.  With the images moved into columns rather than rows, you could have a single row in the table for each of your layout options, and use visibility to hide all but one in each report run. 

     

    Once the SQL is responsible for putting images into columns as needed for your different layouts, you could also have several different overlaid tables, rather than rows in a table, if you prefer.  Again, use visibility and show only one of the tables on each report run.

     

    You could also try to do something similar with a matrix, where the expressions used to determine the breakout of the image rows into columns could handle it.  While I usually find that to be a frustrating exercise it sounds like it might be a fun one to try here <g>.

     

    >L<

     

     

    Thursday, November 8, 2007 5:05 PM
  • Hello Lisa,

    The way i amd oin it is as follow:

    Table:Image Table
    Column1: ImagefilePath           (e.g    file:///c:\user\nadeem\abc.bmp)
    Column2: UserSelection          (e.g    1x1)


    I have matrix and in the coloum part i afev  draged the ImageFilePath as

    Value:  =Field!ImageFilePath.Value


    so now i can see  all images in one row, let say i have 5 images then i can see 5 images in one row.


    now the big part is UserSelection,


    So if it is 2x2 then

    2 rows and 2 images in each row.


    If it is 3x3

    then 3 rows and 3 images in each row. so if there are more images then it will go on the next page.


    and i just have three options 1x1, 2x2, 3x3




    plaese let me know how can i  use this UserSelection


    Thursday, November 8, 2007 9:23 PM
  • I already understand what you want to do and how it is based on user selection.

     

    A matrix is a way I have never done it and in fact have *avoided* doing.

     

    So you're saying that you have chosen to do this in a matrix, but you would like me to work out the expressions for you?

     

    I said that doing it with a matrix is theoretically possible, but I'd have to sit down and work out the kludge that would make it work. Although I said it might be fun, I don't have a superabundance of time to play with this right now, and don't have it ready-made to produce for you.

     

    >L<

     

    Thursday, November 8, 2007 9:35 PM
  • Hello Lisa,


    Its not a requirement to do with matrix but i was just looking at this option. What will be the best way to do it.

    please let me know.


    I am fairly new to this. This would be my first report so i am bit slow in understanding things.


    Thursday, November 8, 2007 9:59 PM
  • 1. If you are a beginner, and unless somebody has the time to walk you through this (which I don't right now -- although I'm starting to think this is another walkthrough I might want to post when I have more time!), I think Eldelo's advice is very good: use a different report for each layout.  However you will still have the "sideways" problem -- how do you get the images across -- which you can resolve by using the code I posted in the thread I referenced earlier:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1884918&SiteID=1

     

    ... did you read that thread, and did you understand it?  This really works out the idea for you, but I do understand you may need me to explain something.  Please read it and ask questions <s>.

     

    2. You can also apply the same idea shown in that "sideways" thread but only have *one* report if you have several overlaid layouts.  I just think it will be very hard to edit and manage, and there is really no advantage over multiple reports for each layout in this case.

     

    3. You have the alternative is to use a matrix but create a grouping condition that varies depending on the layout.  I would have to work out how this is done for you, unless you can do it yourself, as I said; I don't have an example to hand.

     

    4. As another alternative (and this is assuming you are not also a beginner in SQL, just a beginner in reports! and also that your data is in SQL Server 2005) you might be able to fake a matrix using the SQL Server PIVOT clause, as I show in this post: http://spacefold.com/lisa/post/Matrix-Rebuilt-More-non-standard-fun-with-T-SQL.aspx

     

    This is a really cool technique for handling dynamic placement in a table, and it's quite general.  But I would have to sit down and figure how how to do it specific for your data and situation and I just can't right now.

     

    I also don't know whether you have the ability to do the code in SQL Server at all -- quite apart from level of experience, sometimes report developers don't have the appropriate access to do some of this stuff, so I don't know whether it is okay to suggest it.  If it is okay, there might be other variants we could try.

     

    -----------

     

    I am sorry that I can't tell you what is the "best" approach.  I would have to experiment to decide that and while it is fun it is not in scope for my workload for November to have that much fun <sigh>. So, for now, I'm suggesting approach #1 with some use of the "sideways" technique shown in that earlier thread.

     

    >L<
    Thursday, November 8, 2007 10:19 PM
  • Lisa's level of sophistication and experience with the ReportViewer is much greater than mine, and she foresaw an issue with my proposed solution that I hadn't foreseen, but believe I do now.

     

    Reports are fundamentally driven by the table schema, so even if you use three Reports your original schema doesn't change, and that won't allow the scheme I was imaging.

     

    I too do not have time to work this out or be longwinded, but I guess I'd approach the problem with a brute force method...

     

    Construct three table schema's in memory/code, one table with one image per row, one table with two images per row, and one table with three images per row.

     

    I'd then configure the 1x1 Report to use the table with 1 image per row, the 2x2 Report to use the table with 2 images per row, etc.

     

    Then the problem unwinds to one of taking the users' selection, reading the images out of the original table in code (whatever the schema of the original table), and putting them into the appropriate table so that the table has 1 image per row (1x1) , 2 images per row (2x2), or 3 images per row (3x3).

     

    At that point displaying them in a List etc is pretty straightforward.

     

    Shouldn't be too hard, though potentially messy...

     

    Friday, November 9, 2007 2:45 AM
  • BTW, I'm certain there's a more elegant way to solve this issue, and would love to see it if someone has some tricks up their sleeve...

     

     

    Friday, November 9, 2007 5:42 PM
  • Dude, almost done... hold your horses...

     

    This stuff is too hard to format in a forum post, too hard to refer to later, and too hard to amend later.

     

    So I am going to blog-post an example of how to do this in SQL Server 2005 specific syntax.  I will also hard code the example, no dynamic SQL, here, to show how to move those rows into columns for a specific value (I'll use 3 in the example). 

     

    You should be able to see how you could *construct this statement* differently, depending on the value of a parameter that you might call "NumberAcross", and then execute that statement, from the syntax I am showing you.  I will do more later if I have time. 

     

    Here we go. http://spacefold.com/lisa/post/SQL-for-Sideways-Layout-Reports.aspx

     

    >L<

     

    Friday, November 9, 2007 7:30 PM