Switch statement inside a foreach loop - not getting expected results
So I am trying to loop though items that are in a listbox in my
application. The list box will allow you to select multiple items to which
I have a method tied to each item in the listbox. I have a counter
variable incremented each time the loop works.When I use the foreach loop
with the switch statement below, it does the first item correct, but then
loops through the same item again. I know I am missing something as it is
supposed to go to the next item in the listbox and not the same item.
string reportname = lstbxReports.SelectedValue.ToString();
int i = 0;
foreach (var report in reportname)
{
switch (reportname)
{
case "Overview":
{
if (i < 1)
{
PrintOverview(filename);
}
else if (i >= 1)
{
PrintOverviewAppend(filename);
}
break;
}
case "Sources":
{
if (i < 1)
{
PrintSource(filename);
}
else if (i >= 1)
{
PrintSourceAppend(filename);
}
break;
}
}
i++
Any thoughts or suggestions on how I can get the foreach loop to go to the
next item in the selected listbox?
Also, this is just a snippet as I have about 11 case items to loop through.
No comments:
Post a Comment