473,480 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Handling List(Of T) Events in Custom Class

I am writing a class that has a list of strings as one of its
properties. I want to be able to run some code whenever that list of
strings is modified through the class property. Here is the
definition of the property 'JobSites'

Public Class SiteList
Private _JobSites As New List(Of String)
Public Property JobSites() As List(Of String)
Get
Return _JobSites
showSite()
End Get
Set(ByVal value As List(Of String))
_JobSites = value
showSite()
End Set
End Property
End Class

Whenever I add or remove a string from the JobSites list I want to be
able to process the results, for example

Dim Test as new SiteList
Test.JobSites.Add("Example 1") 'At this point, I want the object to
run some code internally

Do I override the List's Add method? Have not had any luck trying to
declare the list as withevents and then overriding the methods that
alter the list. Any suggestions?

Feb 22 '07 #1
6 2328
What is showSite()? Is that the 'internal' code you want to execute. If not
then what is the code you want to execute?
"Bryan" <br*******@gmail.comwrote in message
news:11*********************@s48g2000cws.googlegro ups.com...
>I am writing a class that has a list of strings as one of its
properties. I want to be able to run some code whenever that list of
strings is modified through the class property. Here is the
definition of the property 'JobSites'

Public Class SiteList
Private _JobSites As New List(Of String)
Public Property JobSites() As List(Of String)
Get
Return _JobSites
showSite()
End Get
Set(ByVal value As List(Of String))
_JobSites = value
showSite()
End Set
End Property
End Class

Whenever I add or remove a string from the JobSites list I want to be
able to process the results, for example

Dim Test as new SiteList
Test.JobSites.Add("Example 1") 'At this point, I want the object to
run some code internally

Do I override the List's Add method? Have not had any luck trying to
declare the list as withevents and then overriding the methods that
alter the list. Any suggestions?
Feb 22 '07 #2
On Feb 21, 10:05 pm, "Stephany Young" <noone@localhostwrote:
What is showSite()? Is that the 'internal' code you want to execute. If not
then what is the code you want to execute?
ShowSite() is something that must run if certain properties in the
object are changed. Yes it has the code that I want to run when an
item is added to the JobSite string list.

Feb 22 '07 #3
I really meant ...

What is the code inside showSite?

Where is showSite located?

You say it is 'something' that must run ... but is it THE code you refer to
in your OP or is there othe code that must run as well?
"Bryan" <br*******@gmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
On Feb 21, 10:05 pm, "Stephany Young" <noone@localhostwrote:
>What is showSite()? Is that the 'internal' code you want to execute. If
not
then what is the code you want to execute?

ShowSite() is something that must run if certain properties in the
object are changed. Yes it has the code that I want to run when an
item is added to the JobSite string list.
Feb 22 '07 #4
On Feb 21, 10:25 pm, "Stephany Young" <noone@localhostwrote:
I really meant ...

What is the code inside showSite?

Where is showSite located?

You say it is 'something' that must run ... but is it THE code you refer to
in your OP or is there othe code that must run as well?
ShowSite() is a private sub in the custom class. It handles some GUI
stuff. I call it when certain properties change that affect the GUI.
I need it to run after the JobSites string list is modified in any
way. Right now it will only change if I directly access the JobSites
property, i.e.
Object.JobSites = new List(Of String)
or
dim x as List(Of String) = Object.JobSites

I need it to run when I do:
Object.JobSites.Add("Site 1")
or
Object.JobSites.Remove("Site 2")
etc

Feb 22 '07 #5
By 'custom class' I take it that you mean SiteList?

If so then it is something like:

Public Class SiteList

Private _JobSites As New List(Of String)

Public Sub New()

showSite()

End Sub

Public Sub Add(ByVal value As String)

_JobSites.Add(value)

showSite()

End Sub

Public Function Remove(ByVal value As String) As Boolean

Dim _result as Boolean = _JobSites.Remove(value)

showSite()

Return _result

End Sub

Public Property JobSites() As List(Of String)

Get
Return _JobSites
End Get

Set(ByVal value As List(Of String))
_JobSites = value
showSite()
End Set

End Property

Private Sub showSite()

...

End Sub

End Class
"Bryan" <br*******@gmail.comwrote in message
news:11*********************@m58g2000cwm.googlegro ups.com...
On Feb 21, 10:25 pm, "Stephany Young" <noone@localhostwrote:
>I really meant ...

What is the code inside showSite?

Where is showSite located?

You say it is 'something' that must run ... but is it THE code you refer
to
in your OP or is there othe code that must run as well?

ShowSite() is a private sub in the custom class. It handles some GUI
stuff. I call it when certain properties change that affect the GUI.
I need it to run after the JobSites string list is modified in any
way. Right now it will only change if I directly access the JobSites
property, i.e.
Object.JobSites = new List(Of String)
or
dim x as List(Of String) = Object.JobSites

I need it to run when I do:
Object.JobSites.Add("Site 1")
or
Object.JobSites.Remove("Site 2")
etc
Feb 22 '07 #6
On Feb 21, 11:12 pm, "Stephany Young" <noone@localhostwrote:
By 'custom class' I take it that you mean SiteList?

If so then it is something like:

Public Class SiteList

Private _JobSites As New List(Of String)

Public Sub New()

showSite()

End Sub

Public Sub Add(ByVal value As String)

_JobSites.Add(value)

showSite()

End Sub

Public Function Remove(ByVal value As String) As Boolean

Dim _result as Boolean = _JobSites.Remove(value)

showSite()

Return _result

End Sub

Public Property JobSites() As List(Of String)

Get
Return _JobSites
End Get

Set(ByVal value As List(Of String))
_JobSites = value
showSite()
End Set

End Property

Private Sub showSite()

...

End Sub

End Class
I ended up creating a new class that inherits List(Of String), and
added a custom event called ListChanged that fires whenever add,
delete, clear etc are called. Then my SiteList object can react to
that event. I chose this route because I didn't want to have to
expose every method of List(Of String) through my SiteList object.
Thanks for the help everyone.

Feb 22 '07 #7

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

Similar topics

2
2081
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
4
27919
by: m96 | last post by:
hi, i'm trying to make a query to a ldap server (version v2 or v3 doen't matter) with c#. the query works just fine but the problem is that i can't read the custom attributes/fields, since .net...
4
1295
by: VJ | last post by:
Is there a known way to check programatically the List of events that are attached to a control at runtime. Say i need to know if Click event is attached or not for a button? VJ
0
7522
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
3
4062
by: SenthilVel | last post by:
Hi I want to list the available "Component Services " (COM+) in a machine . i am trying to get the list of Componenet services in a machine using windows forms in dotnet , how can i retrive...
10
5083
by: moondaddy | last post by:
I'm new to c# and .net 2.0. In the old vb.net 1.1 days I normally created a list class for every business class and used this list class for all databinding rather than using datasets. This is...
3
1844
by: UJ | last post by:
Does anybody know of where I can find a complete list of the events that Windows writes to the EventLog ? TIA - Jeff.
7
2173
by: apotheos | last post by:
I can't seem to get this nailed down and I thought I'd toss it out there as, by gosh, its got to be something simple I'm missing. I have two different database tables of events that use different...
2
1158
by: marcotrapanese | last post by:
Hello! I wrote a class "Layers" with one event "DataChanged": Public Class Layers Private _Value as Object Public Property Value() As Object Get
0
7037
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
6904
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...
1
6730
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
6873
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
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.