473,395 Members | 1,977 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,395 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 1290

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.