Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

i was working on a simple task to show some strings to the listbox.
The problem is; if i add 5 items(string) to the listbox, it shows the 1st added item in 5 rows. I want it to show all the added items.

Below is my code:

C#
for (int i = 1; i <= 5; i++)
{
   for (int i = 0; i < 7; i++)
   {
      int iDraw = randomNum.Next(1, 1000000);
      ListNumContainer.Add(iDraw);
   }
   for(int i = 0; i < ListNumContainer.Count; i++)
   {
        strBlder.AppendFormat(Convert.ToString(ListNumContainer[i]));
        if(i!=5)
          strBlder.Append("-");
   }
   listBox.Items.Add(strBlder);
}


The ListNumberContainer contains some int and will be appended to the stringbuilder before added to the listBox.

Is there anything which i have missed out?
And what is the difference between ListBox,ListBoxItem,ListView and ListViewItem?

Thanks,
Skunkhead :)
Posted
Updated 23-Dec-10 18:57pm
v3
Comments
Tarun.K.S 24-Dec-10 0:58am    
Uncheck this checkbox when inserting code snippets : Ignore HTML in text (good for code snippets)
Dr.Walt Fair, PE 24-Dec-10 1:23am    
Where do you initialize strBlder? Why do you use int i in nested loops? I'm surprised the compiler even allows that!

Thanks guys for all your comments and reply. Appreciate it.

This problem was due to StringBuilder object declared as global variable. I have change it to be a local variable and this fix the problem.

Thx.
 
Share this answer
 
I can see control variable "i" used in two loops nested into each other. It's a mistake

Also, please look at the page. Could you correct formatting of HTML entities -- hard to read. Look at this page's edit box -- it has options like "allow HTML", "escape HTML characters", etc.

And what is the differences between ListBox,ListBoxItem,ListView and ListViewItem? Well, approximately the same as the difference between apple and ballerina.
Seriously, Microsoft provides very good documentation on those. Just reading and understanding them will cost you much less than even formulating your questions (of course, in more or less correct way, so anyone would volunteer to answer).
 
Share this answer
 
Comments
Espen Harlinn 26-Feb-11 11:13am    
My 5
Sergey Alexandrovich Kryukov 26-Feb-11 19:14pm    
Thank you.
This is another issue which looks abandoned by OP.
There a many of those. Help is often not helping.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900