473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Problem with ListBox

I have a weird problem with a sorted ListBox which is bound to an ArrayList.

My ArrayList is holding a collection of custom objects. One of the public properties is called Name. When I add a few objects to the list and then bind the ArrayList to the ListBox (and after setting the DisplayMemeber property to "Name") the names show up like that are supposed to.

If I then add a new element to the ArrayList and call the Refresh method of the CurrencyManager object the ListBox shows the correct number of elements but instead of the value of the Name property it shows the full name of the class.

If I set the Sorted property of the ListBox to false everything works fine.

What am I missing or doing wrong?

Thanks

- Jason
I posted sample code below :

TestClass

public class TestClass
{
private String _name;

public TestClass(String name)
{
_name = name;
}

public String Name
{
get { return _name; }
}
}

Form with ListBox (and button to add new element)

private void Form1_Load(object sender, System.EventArgs e)
{
_list = new ArrayList();
_list.Add(new TestClass("Jason"));
_list.Add(new TestClass("Mary"));

listBox1.DataSource = _list;
listBox1.DisplayMember = "Name";
}

private void button1_Click(object sender, System.EventArgs e)
{
_list.Add(new TestClass("Vinny"));

CurrencyManager cm = (CurrencyManager) listBox1.BindingContext[_list];
cm.Refresh();
}
Jul 21 '05 #1
0 1286

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt Sawyer | last post by:
Hi, I'm attempting to do a drag and drop operation from one listbox to another. I have my listboxes setup with SelectionMode = MultiExtended so that I can use the shift key, cntrl key, etc. to...
1
by: Josema | last post by:
Hi to all, I have a class (persons) that derives from collection base: and another class (person) with this properties: -ID -Name When i have complete filled the object Persons with all...
3
by: Lloyd Sheen | last post by:
I have a page that works fine. I am trying to optimize the page by overriding some of the Information that is being saved in the hidden VIEWSTATE. If I make the properties of the dropdown False...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
0
by: Ken Varn | last post by:
I have a strange problem with a databound listbox. It may be because of how I use it, but I am stumped by this behavior. Here is the scenario: I have a multiselect databound listbox that...
4
by: amber | last post by:
Hello I'm not sure if I should give up trying to find an answer here...or just keep posting my problem.. I'm having problems with a listbox.. I have a listbox that is populated when a user...
2
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: -------------------------------...
5
by: Alien2_51 | last post by:
I have a problem with a ListBox control that is on a TabControl, it seems to be forgetting which items are selected in the list when I tab off the current tab, here's my winform code... I even...
1
by: Mart?n Llanos via .NET 247 | last post by:
I've this problem, in my aspx i put a ListBox, when i add lines to this ListBox and and click de button "Guardar", a java script function is called. In that java script I have this code: var...
1
by: faheem ramzan via .NET 247 | last post by:
I have a problem using listbox. I used to put items in listbox dynamically and maintained size automatically in listbox sothat there is no scroll bar in the listbox. I have a problem when the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.