Advertisement Jump to content
Sign in to follow this  

.NET/C# - listbox problem: item text does not show

This topic is 4888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an odd problem with Visual Studio .NET's listbox. When I create a listbox, and add a number of items, the items are added, but their text is not displayed in the listbox like this: Now, this would be only half a problem if I could pinpoint this to a code problem, but it doesn't seem to be so. I sent the code to a colleague, he ran the app, and he got the items shown in the listbox as it should. The only notable difference is in the C# version we have: I have Microsoft Visual C# .NET 69586-335-0000007-18787 He has Microsoft Visual C# .NET 69462-335-0000007-18451 I verified this with some VB.NET code, and the same problem occurs there. I also tried the code on a machine with the same version as I have, but it wouldn't display the text either. There is nothing to be found on the web about a comparable problem, so I'm kind of stuck on this. Here is the code anyway. It's the button handler code so:
			// Create an instance of the ListBox.
			ListBox listBox2 = new ListBox();
			// Set the size and location of the ListBox.
			listBox2.Size = new System.Drawing.Size(200, 100);
			listBox2.Location = new System.Drawing.Point(10,10);
			// Add the ListBox to the form.
			// Set the ListBox to display items in multiple columns.
			listBox2.MultiColumn = true;
			// Set the selection mode to multiple and extended.
			listBox2.SelectionMode = SelectionMode.MultiExtended;
			// Shutdown the painting of the ListBox as items are added.
			// Loop through and add 50 items to the ListBox.
			for (int x = 1; x <= 50; x++)
				listBox2.Items.Add("Item " + x.ToString());
			// Allow the ListBox to repaint and display the new items.
			// Select three items from the ListBox.
			listBox2.SetSelected(1, true);
			listBox2.SetSelected(3, true);
			listBox2.SetSelected(5, true);

			// Display the second selected item in the ListBox to the console.
			// Display the index of the first selected item in the ListBox.

I hope someone can tell me how to solve this problem, or point me in the direction of the solution. Thanks in advance!

Share this post

Link to post
Share on other sites
I found the solution, for those who are interested:

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!