473,385 Members | 1,693 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,385 software developers and data experts.

Listbox item not a string object, updating items

As a Listbox.item, rather than using a string I'm using a ListItems object,
overriding the ToString method
When I add items to listbox.items, my strings are shown correctly.
On the otherhand, when I update the "value" field the listbox doesn't update
to reflect the new value.
What do I need to do to the following code to correct this please (if it's
possible) ?

public class ListItems

{

public bool IsUser = false;

public string value = "";
public ListItems(string Text, bool IsUser)

{

this.IsUser = IsUser;

value = Text;

}

public override string ToString()

{

return value;

}

}
Nov 16 '05 #1
1 6312
Hi,
The class seems fine, I think that what happen is that the listbox has no
way to know (implicitly) that the content of the item changed, so basically
you need to force it to update, I can think of 3 methods ( not sure of the
best nor if they work )

1- Call Invalidate on the listbox, it does force a paint on it. A similar
approach will be calling Refresh()
2- Call ListBox.RefreshItem( index )
3- Remove/Insert the item in the Items collection.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Claire" <cc@hotmai1.com> wrote in message
news:35*************@individual.net...
As a Listbox.item, rather than using a string I'm using a ListItems
object, overriding the ToString method
When I add items to listbox.items, my strings are shown correctly.
On the otherhand, when I update the "value" field the listbox doesn't
update to reflect the new value.
What do I need to do to the following code to correct this please (if it's
possible) ?

public class ListItems

{

public bool IsUser = false;

public string value = "";
public ListItems(string Text, bool IsUser)

{

this.IsUser = IsUser;

value = Text;

}

public override string ToString()

{

return value;

}

}

Nov 16 '05 #2

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

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
1
by: Patty O'Dors | last post by:
Hi I have some code to create an ownerdrawn listbox (derived), and when I add an item to it, the bold text of the first item (the title, 'Collections and Maturities') mysteriously seems to get...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
6
by: Sparky Arbuckle | last post by:
The code below works to an extent. The problem with it is that no matter which item is selected, the first one in the list is always the item that gets added/removed. How can I alleviate this...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
7
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
3
by: CSharper | last post by:
Is it possible to selectivly change the color of an item in text. I saw ForeColor option, but it changes the color of all the items. If it is not possible, is there any other control list listbox...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.