Skip to main content
gamedev.net
🔒 Locked

c# listbox problem

Started by j0mich01 0 replies 2.9k views
Original Post
j0mich01
j0mich01
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.
My_Mind_Is_Going
My_Mind_Is_Going
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    

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.