0

Below is my C# code to populate the multi-selected items from the listbox

List<string> listCountry = new List<string>();
for (int i = 0; i < lstCountry.Items.Count; i++)
{
   if (lstCountry.Items[i]Selected)
   {
       countries = listCountry.Add(lstCountry.Items[i].ToString());
    }
}     

And I have a line to call the method to run the report with the above parameters:

retVal = CR.GetReport(Company, countries);

My question is : What data type should I define for countries since it keeps giving me error like "can't implicitly convert type 'void' to 'string'" when I define countries as string countries = null; What did I do wrong here? Please help, thank you very much

Sorry I didn't make it clear enough, I have another the function GetReport() which is defined as

public CrystalDecisions.CrystalReports.Engine.ReportDocument GetReport( string      Company,  string countries)
{
    CrystalDecisions.CrystalReports.Engine.ReportDocument retVal = new rptReortData();
     ReportLogon rptLog = new ReportLogon();
     rptLog.logon(retVal, "Report");
     retVal.SetParameterValue("P_Country", new string[] { country});
}  

How do I get the value from the listbox assign to countries

0

4 Answers 4

2

You didn't provide the name of your function but I guess it's GetReport. It doesn't return any value so you can't assign the retVal. Try the below:

CR.GetReport(Company, countries);
Sign up to request clarification or add additional context in comments.

1 Comment

I added the function GetReport(). What did I do wrong there ?
0

I'm a little puzzled by your question, but I'm guessing that the CR.GetReport function is raising an exception? So your data-type for countries depends on that function.

I might make the following change:

listCountry.Add((lstCountry.Items[i] == null ? string.Empty : lstCountry.Items[i].ToString()));

Comments

0
List<string> listText = new List<string>();
List<string> listValue = new List<string>();
foreach (int index in ListBox1.GetSelectedIndices()) {
    listText.Add(ListBox1.Items[index].Text);
    listValue.Add(ListBox1.Items[index].Value);
}

Comments

0

You need to return retVal from your function

public CrystalDecisions.CrystalReports.Engine.ReportDocument GetReport( string      Company,  string countries)
{
    CrystalDecisions.CrystalReports.Engine.ReportDocument retVal = new rptResearchDataDownload();
     ReportLogon rptLog = new ReportLogon();
     rptLog.logon(retVal, "Report");
     retVal.SetParameterValue("P_Country", new string[] { country});

    // ADD THIS LINE
    return retVal;

}  

Also you need convert the list to a string. You can do this like this:

countries = listCountry.Aggregate((list, c) => list + c + ",");

3 Comments

Yes, I added that, it works well on that part, thank you very much. However, the data type of list<string> conflict with countries.
Hi Bartosz, what is <b>list</b>, it doesn't show up in my VS2010 intelligence after I typed Aggregate
list is the name of the argument for the lambda expression. You can name it anything you what e.i. 'l' for short.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.