HighTechTalks DotNet Forums  

Found bug in ListBox control (.NET 3.5)

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss Found bug in ListBox control (.NET 3.5) in the Dotnet Framework (WinForms Controls) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jeff
 
Posts: n/a

Default Found bug in ListBox control (.NET 3.5) - 05-19-2010 , 10:30 AM






Hello world,

I am just trying to get this written down somewhere, in hopes that
someone at Microsoft will see it and turn in the bug.

The ListBox control does not properly sort its items if you set the
Sorted property to true, and bind it to an IList.

For example, here is a simple class that I can make an array of
(arrays implement IList):
public class ItemBox
{
public string DisplayMemberStr
{
get;
set;
}
public string ValueMemberStr
{
get;
set;
}
}

Now, I initialize my listbox in a form_load method like so:
ItemBox[] iBox = new ItemBox[7];
iBox[0] = new ItemBox() { DisplayMemberStr = "Display5",
ValueMemberStr = "Value5" };
iBox[1] = new ItemBox() { DisplayMemberStr = "Display1",
ValueMemberStr = "Value1" };
iBox[2] = new ItemBox() { DisplayMemberStr = "Display3",
ValueMemberStr = "Value3" };
iBox[3] = new ItemBox() { DisplayMemberStr = "Display4",
ValueMemberStr = "Value4" };
iBox[4] = new ItemBox() { DisplayMemberStr = "Display6",
ValueMemberStr = "Value6" };
iBox[5] = new ItemBox() { DisplayMemberStr = "Display7",
ValueMemberStr = "Value7" };
iBox[6] = new ItemBox() { DisplayMemberStr = "Display2",
ValueMemberStr = "Value2" };

lbTest.DataSource = iBox;


Note that in my designer, I have set the Sorted property to true, and
set the display and value member properties at design-time, like this:
//
// lbTest
//
this.lbTest.DisplayMember = "DisplayMemberStr";
this.lbTest.FormattingEnabled = true;
this.lbTest.Location = new System.Drawing.Point(12, 12);
this.lbTest.Name = "lbTest";
this.lbTest.Size = new System.Drawing.Size(266, 251);
this.lbTest.Sorted = true;
this.lbTest.TabIndex = 0;
this.lbTest.ValueMember = "ValueMemberStr";
this.lbTest.SelectedIndexChanged += new
System.EventHandler(this.lbTest_SelectedIndexChang ed);

I also attached a simple onSelectedIndexChanges event, like this:

private void lbTest_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbTest.SelectedIndex > -1)
{
if (lbTest.SelectedValue == null)
{
txtTest.Text = "NULL";
}
else
{
txtTest.Text = lbTest.SelectedValue.ToString();
}
}
}

This simply puts the value in a textbox as I click items in the
listbox.

If you run a Visual Studio solution that does this, you'll see the
bug. Clicking Display2 will show Value1, for example.

FYI. I could care less if it gets fixed. I found no good way to
submit a Microsoft bug (about like this person's experience:
http://weblog.timaltman.com/archive/2006/03/22/reporting-bugs-microsoft
)

There you go! Sure would be great to see an easier place to turn in
Microsoft bugs without charging your client base.

Reply With Quote
  #2  
Old   
Herfried K. Wagner [MVP]
 
Posts: n/a

Default Re: Found bug in ListBox control (.NET 3.5) - 05-29-2010 , 07:24 PM






Am 19.05.2010 17:30, schrieb Jeff:
Quote:
FYI. I could care less if it gets fixed. I found no good way to
submit a Microsoft bug (about like this person's experience:
http://weblog.timaltman.com/archive/2006/03/22/reporting-bugs-microsoft
)
You are looking for Microsoft Connect.

<URL:http://connect.microsoft.com/>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.