473,407 Members | 2,676 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,407 software developers and data experts.

Editing items text an Listbox

I've class derived from "Object" class, with ToString() method overriden
itc. ,
now i add object of this class to Windows.Forms.ListBox.Items
collection, and it works fine, displaying what ToString() should return...

then the program is in the runtime, i chage fields of this object in thet
way ( (MyClass)ListBox.SelectedItem ).SomeProperty = newValue;
so ToString() method now will return new value, but text showed in a listbox
itself not changes, i tried to call ListBox.Update(), adn ListBox.Text = "",
but nothing worked...
What can i do?
Nov 15 '05 #1
2 13424
Hi,

int selectedIndex = ListBox.SelectedIndex;
MyClass selectedItem = (MyClass)ListBox.SelectedItem;
.....
selectedItem.Property = newProperty;
.....
ListBox.Items[selectedIndex] = selectedItem;

I've class derived from "Object" class, with ToString() method overriden
itc. ,
now i add object of this class to Windows.Forms.ListBox.Items
collection, and it works fine, displaying what ToString() should return...

then the program is in the runtime, i chage fields of this object in thet
way ( (MyClass)ListBox.SelectedItem ).SomeProperty = newValue;
so ToString() method now will return new value, but text showed in a listbox itself not changes, i tried to call ListBox.Update(), adn ListBox.Text = "", but nothing worked...
What can i do?

Nov 15 '05 #2
i've done like you proposed, it's my code:

CheesDrawing.Player.csPlayer Player =
(CheesDrawing.Player.csPlayer)lstPlayers.SelectedI tem;
Player.Name = txtName.Text;
lstPlayers.Items[lstPlayers.SelectedIndex] = Player;

third line throws exeption:
"object reference not set to an instance of an object"

"PL Patrick" <ne********@user.pl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

int selectedIndex = ListBox.SelectedIndex;
MyClass selectedItem = (MyClass)ListBox.SelectedItem;
....
selectedItem.Property = newProperty;
....
ListBox.Items[selectedIndex] = selectedItem;

I've class derived from "Object" class, with ToString() method overriden
itc. ,
now i add object of this class to Windows.Forms.ListBox.Items
collection, and it works fine, displaying what ToString() should return...
then the program is in the runtime, i chage fields of this object in thet way ( (MyClass)ListBox.SelectedItem ).SomeProperty = newValue;
so ToString() method now will return new value, but text showed in a

listbox
itself not changes, i tried to call ListBox.Update(), adn ListBox.Text =

"",
but nothing worked...
What can i do?


Nov 15 '05 #3

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

Similar topics

1
by: DCount17 | last post by:
I have used the following code, but I get an error. I'm using C#. When the checkbox is selected, I want to select all items in lstTeams (90 items) so the user doesn't have to manually select each...
3
by: SamIAm | last post by:
Hi I have a ListBox called lstListOfStuff I want to get the ordinal position of a ListItem so that I can insert a new ListItem below it. How do I do this? I cannot find any members to give me...
2
by: Diggler | last post by:
I have a group of items in the database that need to be sorted by the client. There is a field in the database that stores the desired order (0, 1, 2, etc...). I would like to allow the client to...
3
by: kimiraikkonen | last post by:
Hi, I want to display ALL the items (includes unselected items) of listbox control. How can i code this? Should i use "for each" or other? For example: Assume you have a listbox with 3 items...
2
by: Ramk | last post by:
I have a listbox on my form which is bounded to a bindingsource. The collection is of type List<T>. If I add new elements to the bindingsource, I would like to select them in the listbox. A...
14
by: yookify | last post by:
Im Using asp .net with Vb Coding. I have to remove the list of selected items from listbox . Dim i As Integer For i = 0 To listbox1.Items.Count - 1 ...
0
by: MeMeSo | last post by:
Hi I appreciate your help in advance. I'm new to VBA - and would like to know how to add and remove items from a listbox (not the main table) via a subform instantly. 1. Code to populate listbox...
13
by: Connect | last post by:
hi i have qusetion how to remove ongy blank items from listbox? I mean I wanna make button that only remove blank items from listbox
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: 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
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
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
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...

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.