开发者

SSRS Report Multiparameter from WinForm ListBox C#

I have a form which I want the user to be able to export to a PDF/Print off, so I included a report viewer and have sent the values over as parameters.

All these have worked fine except for the ListBox which I'm running into problems with.

This ListBox has some possible number of items in it which I would like to send over to the report for display.

Currently have:

 List<string> passengersParameter = new List<string>();

 for ( int i = 0 ; i < moreForm.passengerListBox.Items.Count ; i++ )
 {
     passengersParameter.Add( moreForm.passengerListB开发者_开发问答ox.Items[i].ToString() );
 }

 parameters.Add( new ReportParameter("passengerList", passengersParameter.ToArray()));

This displays the first entry of the list just fine when I have the parameter added on the report, however, when I set it to Text and select Allow Multiple Values the parameter just displays #Error

Is there something else I need to do in order for it to display all the values from the array? I'm at a loss.


Finally figured out how to get this to work.

Apparently we can't just pass a list into the report: we need to add a DataSet.

So for my example above

testData chaos = new testData();

...

foreach ( Passenger victim in showMe.Passengers )
        {
            // msdn.microsoft.com/en-us/library/5ycd1034(v=VS.100).aspx
            DataRow skeez = chaos.Tables["Victims"].NewRow();

            skeez["Name"] = victim.ToString();

            chaos.Tables["Victims"].Rows.Add( skeez );
        }

        this.victimsBindingSource.DataSource = chaos.Tables["Victims"];

Just make sure to add a DataSet to the report then set it programatically with your populated data (above).

Then (if using VS 2010) make sure to choose the DataSource on the Report Viewer and also set the BindingSource (should automatically be generated by VS).

Hopefully that helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜