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

Array Element Changed Event - How?

All,

Thanks in advance for any help. I am attempting to write a property
that is an array of strings. I am trying to trap the event when one of
the strings in the array changes.

When I step through the code, I can walk through the Set statement when
the length of the array changes (and therefore trap anything I want),
but if one of the elements change, it does not go through the
statement. I am attempting to write my own control from scratch, so I
would like to be able to edit the Labels property on the property grid.
I can do so now, but like I said, I cannot trap the event when a data
element changes. Here is my code:

Dim m_Labels() As String

Property Labels() As String()
Get
Return m_Labels
End Get
Set(ByVal Value As String())
m_Labels = Value
RaiseEvent Changed()
End Set
End Property

Can anyone help me determine how to raise the event 'Changed' if the
value of one of the elements of the array changes?

Thanks!

Nov 23 '05 #1
4 2750
You need to declare a public event

Public Event MyEvent( sender as object, e as eventargs)

. . .

In your code

Raiseevent MyEvent( yourSenderObject, yourEventArgs )

.. . . . .

In the receiving class.

Private Withevents MyClass1 as MyClass

private sub MyEvent1_MyEvent( sender as object, e as eventargs ) Handles
MyClass1.Changed

HTH


--
Best Regards

The Inimitable Mr Newbie º¿º
"JonathanG" <Jo****************@gmail.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
All,

Thanks in advance for any help. I am attempting to write a property
that is an array of strings. I am trying to trap the event when one of
the strings in the array changes.

When I step through the code, I can walk through the Set statement when
the length of the array changes (and therefore trap anything I want),
but if one of the elements change, it does not go through the
statement. I am attempting to write my own control from scratch, so I
would like to be able to edit the Labels property on the property grid.
I can do so now, but like I said, I cannot trap the event when a data
element changes. Here is my code:

Dim m_Labels() As String

Property Labels() As String()
Get
Return m_Labels
End Get
Set(ByVal Value As String())
m_Labels = Value
RaiseEvent Changed()
End Set
End Property

Can anyone help me determine how to raise the event 'Changed' if the
value of one of the elements of the array changes?

Thanks!

Nov 23 '05 #2
Dear Jonathan,

I don't know the exactual implementation, however, I do think you could bind
your array and listen for the binder's changed event.
This would be sort of the same like when you do data binding, instead you
now use an array. If I am not mistaken, the binding class that achieves this
binding has change-events that you can use. I am not quite sure however.

I hope this helps you with answering your question,

Michel van den Berg

"JonathanG" <Jo****************@gmail.com> schreef in bericht
news:11********************@g14g2000cwa.googlegrou ps.com...
All,

Thanks in advance for any help. I am attempting to write a property
that is an array of strings. I am trying to trap the event when one of
the strings in the array changes.

When I step through the code, I can walk through the Set statement when
the length of the array changes (and therefore trap anything I want),
but if one of the elements change, it does not go through the
statement. I am attempting to write my own control from scratch, so I
would like to be able to edit the Labels property on the property grid.
I can do so now, but like I said, I cannot trap the event when a data
element changes. Here is my code:

Dim m_Labels() As String

Property Labels() As String()
Get
Return m_Labels
End Get
Set(ByVal Value As String())
m_Labels = Value
RaiseEvent Changed()
End Set
End Property

Can anyone help me determine how to raise the event 'Changed' if the
value of one of the elements of the array changes?

Thanks!

Nov 23 '05 #3
In regards to Mr. Newbie's response: The idea works, but only for
classes I define or inherit from. I want an event to fire when a
string changes. I cannot inherit from this 'Class'

RE: Michel: Can you elaborate, or point me in the direction of how
databinding is accomplished?

Thanks!

Nov 23 '05 #4
Dear Jonathan,

after looking further into it, I have to inform you that the way I described
is not a very good one. What you should do IMO is create your own collection
and 'expose' the OnSet functionality. For example, you could raise your own
custom made OnSet event when the (protected) OnSet function of the
collection is called. I, myself, would probally implement from
collectionbase
(http://msdn.microsoft.com/library/de...lasstopic.asp).
Note: There is an example on that page. Replace Int16 with String and raise
your event like I said before.

Michel van den Berg
"JonathanG" <Jo****************@gmail.com> schreef in bericht
news:11*********************@g43g2000cwa.googlegro ups.com...
In regards to Mr. Newbie's response: The idea works, but only for
classes I define or inherit from. I want an event to fire when a
string changes. I cannot inherit from this 'Class'

RE: Michel: Can you elaborate, or point me in the direction of how
databinding is accomplished?

Thanks!

Nov 23 '05 #5

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

Similar topics

3
by: Eric | last post by:
Hi, On my form, I turn the forecolor blue when an element's value changes by comparing a custom "origVal" tag on each element. This works fine. Then, when the user resets the form (double...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
32
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains...
5
by: Mircea Dragan | last post by:
Hi, I have a problem. Here is the description: I have a dll which I call from a C# program. The C# program passes an array of doubles to the dll function. Everything works fine as long as I...
2
by: David Veeneman | last post by:
Is there a way that a class can subscribe to an event published by an object that is a member of an array? I have a class, Widget, that maintains information on a widget. I have a number of...
0
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
0
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
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
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,...
1
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...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.