Home:ALL Converter>ReportViewer - how to populate some columns programmatically

ReportViewer - how to populate some columns programmatically

Ask Time:2012-09-22T04:47:24         Author:BonTemps

Json Formatter

I am trying to use reportviewer to generate a report. I am using vb.net, Visual Studio 2010, in Winforms local mode.

I have got it working except for the small columns. I use my business object for the dataset. My problem is that I do not want to put an individual property in my business object for each and every day in the report. (the numbered columns) I know it would work to have an individual property for each day in my business object, but that just seems like a hack. I want to be able to fill in the columns from a list in my own form load code. I want to do something like this (pseudocode)

for each row
 for each daycolumn
      daycolumn_x.text = value from my list of calculation
  end for 

end for

I can not for the life of me find how to refer to or access the columns (possibly because it's the wrong way to do it!?) Any suggestions to access the table entries in the report, or a better way altogether to accomplish this? Thank you for reading this far... (PS I know there is somewhat of a similar question regarding lists, but I do not think it is the same thing. I don't think a subreport would work for this)

This is what I'd like it to look like:

oops -- it says I am not yet allowed to post an image, so here is my attempt to show what I want: (these are column headings)

Employee Name ID Rate 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 total

Here is the code for my form that contains the reportviewer

Public Class frmReport

Private Sub frmReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub ReportViewer2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewer2.Load

    Dim c As Employee   ' this is my business object, for the name, rate, id
    Dim eList As List(Of Employee)

    eList = getAllEmployees()  ' get a list of employees 

    Me.EmployeeBindingSource.DataSource = eList

    ' Here is where I want to fill in the dates columns on my own 

End Sub

Author:BonTemps,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12537950/reportviewer-how-to-populate-some-columns-programmatically