Jump to content
  • Advertisement
Sign in to follow this  
Structural

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

This topic is 4682 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.
			this.Controls.Add(listBox2);
			// 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.
			listBox2.BeginUpdate();
			// 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.
			listBox2.EndUpdate();
      
			// 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.
			System.Diagnostics.Debug.WriteLine(listBox2.SelectedItems[1].ToString());
			// Display the index of the first selected item in the ListBox.
			System.Diagnostics.Debug.WriteLine(listBox2.SelectedIndices[0].ToString());


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
Advertisement
I found the solution, for those who are interested:

http://groups.google.nl/group/microsoft.public.dotnet.framework.windowsforms/browse_thread/thread/c884d4cbf3c8495d/afbab0946de78149?lnk=st&q=listbox+text+.net+bug&rnum=16&hl=nl#afbab0946de78149

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!