# c# listbox problem

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

## Recommended Posts

I've been having a lot of problems trying to get a listbox update in the ways that I want it to. The problem is that whenever I change the text of an object in the listbox, the change doesn't get displayed. This can be fixed a number of ways (calling Listbox.refresh or Listbox.Items = newlistboxitem), but then the listbox decides that it's gonna go ahead and redraw itself and as a result it causes a lot of flicker. I've tried using a Data source as well and it does the exact same thing. Basically I want to call something like this. Listbox1.invalidate(Listbox1.GetItemRect(index)); But just calling this doesn't update the string - But the only things that update the string, completely redraw the whole control. So I've decided there is no way to get around this without deriving my own control and seeing if there is any way to manually update a string in the listbox without triggering a complete redraw. And thats kinda where I'm at right now. If anyone has any suggestions it would be much appreciated.

##### Share on other sites
If you store your objects in a BindingList and then set ListBox.DataSource equal to your list and ListBox.DisplayMember equal to the public property that returns the text you want to display it should handle the updates for you automatically.

For example:

class Foo{     public string Name     {          get { return name_; }          set { name_ = value; }     }     string name_;}// and then assuming you have a ListBox called 'listbox' created somewhere            BindingList<Foo> list = new BindingList<Foo>()listbox.DataSource = listbox;listbox.DisplayMember = "Name";Foo bar = new Foo();bar.Name = "original name";            list.Add(bar);     // you should see bar appear in the listboxbar.Name = "new name"; // and now the name should be updated in the listbox

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633710
• Total Posts
3013482
×