ListBox events
-
Hello, I was playing around with the listbox control in visual c# express edition and I become frustrated when I couldnt find events such as OnInsert / AfterInsert and so on. Has Microsoft reduced events?
-
There has no OnInsert or AfterInsert, but listbox has ControlAdded and ControlRemoved, see if it's help.
-
I have looked at both events(ControlAdded and ControlRemoved) prior to my post, the documentation states they are for controls, not items. How to get notified after new item has been added to the listbox ?
Deian wrote:
I have looked at both events(ControlAdded and ControlRemoved) prior to my post, the documentation states they are for controls, not items. How to get notified after new item has been added to the listbox ?
I had encountered the same problem before. I couldn't find any such event that was usable. What I ended up doing, while it was extremely generic, was take a collection of all the items in the listbox, and compare the collection and the list, and when the count is different, you can "fire your event." It is pretty simple to find the item that has been added or removed. Like I said, it is pretty generic and crappy. But, it got the job done. Worked just fine for me.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
-
Deian wrote:
I have looked at both events(ControlAdded and ControlRemoved) prior to my post, the documentation states they are for controls, not items. How to get notified after new item has been added to the listbox ?
I had encountered the same problem before. I couldn't find any such event that was usable. What I ended up doing, while it was extremely generic, was take a collection of all the items in the listbox, and compare the collection and the list, and when the count is different, you can "fire your event." It is pretty simple to find the item that has been added or removed. Like I said, it is pretty generic and crappy. But, it got the job done. Worked just fine for me.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
-
Thanks for the replies. There are several ways to get out of the situation, but I tought that I am missing something when reading the documentation. Regards, Deian
Deian wrote:
I tought that I am missing something when reading the documentation.
Oh, unfortunately, and strangely enough, you are not.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")