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

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

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 :-)

Apr 27 '07 #1
1 1367
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#
"pl*************@gmail.com" 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 :-)

Apr 27 '07 #2

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

Similar topics

3
by: Marc L'Ecuyer | last post by:
Hi, I have a collection class derived from CollectionBase. This collection can add items of my class MyItem. In my class MyItem, I have a Selected property. When this property is set to true, I...
9
by: Gerald Lightsey | last post by:
I am doing some work that involves automating MS MapPoint 2002. The object model is documented in the context of Visual Basic 6.0. A typical example follows. 'Output first result of find...
2
by: Ash Jones | last post by:
I trying to do nested items in a collection. I've got an item which one of the properties is subitems, which is a collection of item. can do the root level but if i do a subitem at design time i...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
1
by: Alex K. | last post by:
Hi all How do I catch an event when list item is deleted from ListBox? Is there such event? Thank you Alex
2
by: meyousikmann | last post by:
This will be difficult to explain so bear with me. If anyone is familiar with Tibco Rendezvous and/or Microsoft Messaging, this may make more sense. I've created a hierarchy of objects that...
2
by: planet.creativa | last post by:
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...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
1
by: =?Utf-8?B?anVzdGFnZWV6ZXI=?= | last post by:
I feel I'm maybe barking up the wrong tree here, but can I write a collection class (inheriting from collections.generic.list or similar) that can capture events thrown by the list items? E.g: ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.