Listbox text update problem

J

josephbubba

I'm having a problem with a simple ListBox control.

When I try to update an item in the listbox, and only the case of the
item is changing, the displayed contents do not update.

The simple app below can be used to demonstrate the problem. It simply
adds one item "Page 2" to a listbox (listBox1) during the form load.
In a button handler, it attempt to update the text for the item to
"PAGE 2".

The interesting thing is that if I clear the field (with a "") first
before performing the update, everything works fine. Also, if I look
at the contents of the list box in the debugger, the field is properly
updated to "PAGE 2", it just doesn't update on the form.

Note, if you change the text to anything other than a case insensitive
match, everything works just fine. My assumption is that there is
some underlying logic in the list box to avoid redrawing if there are
no "changes". Perhaps there is a property that I'm not aware of.

Any info would be appreciated.


Sample app:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Page 2");
listBox1.SelectedIndex = 0;
}

private void button1_Click(object sender, EventArgs e)
{
int selectedIndex = this.listBox1.SelectedIndex;
//this.listBox1.Items[selectedIndex] = ""; //
uncomment this and it will refresh correctly
this.listBox1.Items[selectedIndex] = "PAGE 2";
}
}
 
O

Oliver Sturm

Hello josephbubba,
I'm having a problem with a simple ListBox control.

When I try to update an item in the listbox, and only the case of the
item is changing, the displayed contents do not update.

Yes, I can reproduce that.
The interesting thing is that if I clear the field (with a "") first
before performing the update, everything works fine. Also, if I look
at the contents of the list box in the debugger, the field is properly
updated to "PAGE 2", it just doesn't update on the form.

Yes. It seems that the list box compares case insensitively and so misses
the change when it's only in the casing of the string. A bug? A
peculiarity of the implementation? I don't know. If it's important to you,
you could search this site, or submit a bug:
http://connect.microsoft.com/feedback/default.aspx?SiteID=210

Your workaround of using an intermediate value seems to work just fine, in
the meantime :)


Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top