Values on Winform and RDLC Report Designer

LabProARW

Active member
Joined
Nov 4, 2019
Messages
39
Programming Experience
1-3
I have a form with a ReportViewer control on it. When the form opens the ReportViewer loads and I see the NumberOfProducts from an expression in the RDLC file. In the expression in the RDLC file II use a text box with this expression: "=CountDistinct(Fields!ProductName.Value)" to get the total number of different products found. I'm drawing a blank on how to take that number and use it elsewhere (like a pie chart on the form that the ReportViewer is on). I should only have to derive that value once - so I resist programmatically finding the same value through code elsewhere in the parent form. Have been trying to reference the RDLC file text box value from the parent form but cannot get the syntax right... or even if that is what I should be doing in the first place.

Thank you for your response.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,250
Location
Sydney, Australia
Programming Experience
10+
I'm drawing a blank on how to take that number and use it elsewhere (like a pie chart on the form that the ReportViewer is on). I should only have to derive that value once - so I resist programmatically finding the same value through code elsewhere in the parent form.
If you only want to get the value once then you're doing it the wrong way around. You don't get a ReportViewer to do work and then get data out of it. You can do the appropriate work in the form and pass the data into the ReportViewer but not the other way around. You can retrieve all the data and do the appropriate processing in the form or you can use a more complex query to do the processing in SQL and get the data in its final form. Either way, you can pass data into a ReportViewer but you don't take it out.
 

LabProARW

Active member
Joined
Nov 4, 2019
Messages
39
Programming Experience
1-3
If you only want to get the value once then you're doing it the wrong way around. You don't get a ReportViewer to do work and then get data out of it. You can do the appropriate work in the form and pass the data into the ReportViewer but not the other way around. You can retrieve all the data and do the appropriate processing in the form or you can use a more complex query to do the processing in SQL and get the data in its final form. Either way, you can pass data into a ReportViewer but you don't take it out.
Let me explain how one gets to the point of asking my question. Using Visual Studio, and following various tutorials I end up getting my report almost looking the way I want. The ReportViewer.rdlc tab on Visual Studio makes it reasonably simple offering the ability to place an 'expression' into a control and to do some grouping. I thought I was OK until needing to add a pie chart to the same report. The pie chart control caused me to go back to code in the form. My total number of products and percentages had been done on the ReportViewer.rdlc, so that is why the question to get that value. I think my difficulty is in using Visual Studio interface to achieve the desired report display. I will follow your direction and use more code in the form and not rely on the function VS has built into the ReportViewer.

Thank you.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,250
Location
Sydney, Australia
Programming Experience
10+
Are you aware that reports can contain charts that can then be displayed by ReportViewer? You may even be able to do it in the same report. Even if it's a separate report, you can probably use the same data source as the other and put the calculations there, or else just duplicate the calculations in the two reports.

I've only ever used charts in server reports but I would assume that client reports would support them too.
 

LabProARW

Active member
Joined
Nov 4, 2019
Messages
39
Programming Experience
1-3
Are you aware that reports can contain charts that can then be displayed by ReportViewer? You may even be able to do it in the same report. Even if it's a separate report, you can probably use the same data source as the other and put the calculations there, or else just duplicate the calculations in the two reports.

I've only ever used charts in server reports but I would assume that client reports would support them too.
I am experimenting with a pie chart in the ReportViewer now. Is there a cache somewhere that holds changes? I have made some changes to the pie chart that are not being reflected on the ReportViewer. It's almost like my RDLC file is not being overwritten with new changes.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,445
Location
Chesapeake, VA
Programming Experience
10+
Considering how in your other thread you already found out how buggy finicky that control can be, I wouldn't be surprised if it has some other buggy odd behaviors.
 
Top Bottom