PC Review


Reply
Thread Tools Rate Thread

How to capture Item's event through an object of its collection in a external class?

 
 
planet.creativa@gmail.com
Guest
Posts: n/a
 
      27th Apr 2007
There are two classes
1) Key - contains some public variables, one method "Reset" and one
event "valuesReset" which is raised by Reset method.
2) Keys - this class is collection of objects of class 'Key' and it is
inherited with ReadOnlyCollection(Of key).
I'm pasting the code here

Class key
Public Event valuesReset()

Public _name As String = ""
Public _title As Integer = 0
Public _strong As Integer = 0
Public _italic As Integer = 0

Public Function reset() As Boolean
_name = ""
_title = 0
_strong = 0
_italic = 0

RaiseEvent valuesReset()
End Function
End Class

'Collection of key
Class keys
Inherits ReadOnlyCollection(Of key)

Friend Sub New()
MyBase.New(New List(Of key))
End Sub

Friend Function add(ByVal tmpKey As key) As Integer
If Items.Contains(tmpKey) Then
Return Items.IndexOf(tmpKey)
End If

Items.Add(tmpKey)
Return Count - 1
End Function

Friend Sub AddAt(ByVal tmpKey As key, ByVal index As
Integer)
If index < 0 OrElse index > Items.Count - 1 Then
Return
End If
If Contains(tmpKey) Then
Return
End If

Items.Insert(index, tmpKey)
End Sub

Friend Sub Dispose()
For i As Integer = Count - 1 To 0 Step -1
Me(i).reset()
Next
End Sub
Friend Sub remove(ByVal tmpKey As key)
Items.Remove(tmpKey)
End Sub
End Class

Class Form1
withevents objKeys as Keys

' I want to capture the "valuesReset" event here with
the index number of the key type
' bject

End Class

Now the problem is how can I capture the event "valuesReset" of an key
object if I use
"withevents objKeys as Keys" in any form/outside class? and if it is
possible how can I know which key object inside the collection has
raised the event? Thanks In advance :-)

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=
Guest
Posts: n/a
 
      27th Apr 2007
You posted this question to a C# newsgroup but used VB code...

I would suggest either creating a new EventArgs-derived class to contain the
key object that is the instigator, or use the sender parameter...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"(E-Mail Removed)" wrote:

> There are two classes
> 1) Key - contains some public variables, one method "Reset" and one
> event "valuesReset" which is raised by Reset method.
> 2) Keys - this class is collection of objects of class 'Key' and it is
> inherited with ReadOnlyCollection(Of key).
> I'm pasting the code here
>
> Class key
> Public Event valuesReset()
>
> Public _name As String = ""
> Public _title As Integer = 0
> Public _strong As Integer = 0
> Public _italic As Integer = 0
>
> Public Function reset() As Boolean
> _name = ""
> _title = 0
> _strong = 0
> _italic = 0
>
> RaiseEvent valuesReset()
> End Function
> End Class
>
> 'Collection of key
> Class keys
> Inherits ReadOnlyCollection(Of key)
>
> Friend Sub New()
> MyBase.New(New List(Of key))
> End Sub
>
> Friend Function add(ByVal tmpKey As key) As Integer
> If Items.Contains(tmpKey) Then
> Return Items.IndexOf(tmpKey)
> End If
>
> Items.Add(tmpKey)
> Return Count - 1
> End Function
>
> Friend Sub AddAt(ByVal tmpKey As key, ByVal index As
> Integer)
> If index < 0 OrElse index > Items.Count - 1 Then
> Return
> End If
> If Contains(tmpKey) Then
> Return
> End If
>
> Items.Insert(index, tmpKey)
> End Sub
>
> Friend Sub Dispose()
> For i As Integer = Count - 1 To 0 Step -1
> Me(i).reset()
> Next
> End Sub
> Friend Sub remove(ByVal tmpKey As key)
> Items.Remove(tmpKey)
> End Sub
> End Class
>
> Class Form1
> withevents objKeys as Keys
>
> ' I want to capture the "valuesReset" event here with
> the index number of the key type
> ' bject
>
> End Class
>
> Now the problem is how can I capture the event "valuesReset" of an key
> object if I use
> "withevents objKeys as Keys" in any form/outside class? and if it is
> possible how can I know which key object inside the collection has
> raised the event? Thanks In advance :-)
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding class object to collection repeats same object through collection? Erazmus Microsoft Excel Programming 2 17th Sep 2007 04:35 AM
How to capture Item's event through an object of its collection in a form? hemant Microsoft Dot NET Framework Forms 1 1st May 2007 11:47 AM
How to capture Item's event through an object of its collection in a external class? planet.creativa@gmail.com Microsoft VB .NET 2 27th Apr 2007 08:23 PM
How to capture Item's event through an object of its collection in a external class? planet.creativa@gmail.com Microsoft Dot NET Framework 0 27th Apr 2007 02:51 PM
How to capture Item's event through an object of its collection in a external class? planet.creativa@gmail.com Microsoft Dot NET Framework 0 27th Apr 2007 02:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:58 PM.