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";
}
}
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";
}
}