Jump to content
  • Advertisement
Sign in to follow this  
j0mich01

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 listbox

bar.Name = "new name"; // and now the name should be updated in the listbox


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!