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

C# EventArgs.Properties are Null when handled in VB.NET

I'm raising an event from a C# component and trying to catch it in a VB.NET Windows application. The VB app recognizes my custom EventArgs object and catches the event. However, when I try to read any of the properties they are null or nothing. The EventArgs object itself is alive and well.

Here's some code:

C# Event

// HANDFOUND EVENT CODE
public event HandFoundEventHandler HandFound;

public delegate void HandFoundEventHandler(object sender,
HandFoundEventArgs e);

public class HandFoundEventArgs : EventArgs
{
// Properties.
public string TableTitle;
public string HandContents;
// Constructor.
public HandFoundEventArgs(string TableTitle, string HandContents)
{
TableTitle = TableTitle;
HandContents = HandContents;
}
}

....function in another class
.... code snipped...time to raise event
HandFoundEventArgs e = new HandFoundEventArgs(tableTitle, handContents);
OnHandFound(e);

finally, here's "OnHandFound"
protected virtual void OnHandFound(HandFoundEventArgs e)
{
if (HandFound != null)
{
HandFound(this, e);
}
}
'-------------------------------------------------------------------------------------------
All this seems to work fine. The following VB.NET code handles the event.

' EVENT HANDLER for the HAND FINDER OBJECT
Private Shared Sub myHandFinder_HandFound(ByVal Sender As Object, ByVal e As HandFoundEventArgs) Handles myHandFinder.HandFound

System.Diagnostics.Debug.Assert(Not e.TableTitle Is Nothing, "Nothing.")
System.Diagnostics.Debug.Assert(Not e.HandContents Is Nothing, "Nothing")

Dim tableNumber As String = ParseTableNumber(e.TableTitle)
'-------------------------------------------------------------------------------

Both Assert return false and first line throws a Null Object Exception.

Thanks for you help,
D

Jul 21 '05 #1
1 2129
Change your constructor for the HandFOundEventArgs to:

public HandFoundEventArgs(string TableTitle, string HandContents)
{
this.TableTitle = TableTitle;
this.HandContents = HandContents;
}

HTH

David

"Diotima" <Di*****@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com:
I'm raising an event from a C# component and trying to catch it in a
VB.NET Windows application. The VB app recognizes my custom EventArgs object
and catches the event. However, when I try to read any of the properties
they are null or nothing. The EventArgs object itself is alive and well.

Here's some code:

C# Event

// HANDFOUND EVENT CODE
public event HandFoundEventHandler HandFound;

public delegate void HandFoundEventHandler(object sender,
HandFoundEventArgs e);

public class HandFoundEventArgs : EventArgs
{
// Properties.
public string TableTitle;
public string HandContents;
// Constructor.
public HandFoundEventArgs(string TableTitle, string HandContents)
{
TableTitle = TableTitle;
HandContents = HandContents;
}
}

...function in another class
... code snipped...time to raise event
HandFoundEventArgs e = new HandFoundEventArgs(tableTitle, handContents);
OnHandFound(e);

finally, here's "OnHandFound"
protected virtual void OnHandFound(HandFoundEventArgs e)
{
if (HandFound != null)
{
HandFound(this, e);
}
}

'---------------------------------------------------------------------------
----------------
All this seems to work fine. The following VB.NET code handles the
event.

' EVENT HANDLER for the HAND FINDER OBJECT
Private Shared Sub myHandFinder_HandFound(ByVal Sender As Object, ByVal e
As HandFoundEventArgs) Handles myHandFinder.HandFound

System.Diagnostics.Debug.Assert(Not e.TableTitle Is Nothing, "Nothing.")
System.Diagnostics.Debug.Assert(Not e.HandContents Is Nothing,
"Nothing")

Dim tableNumber As String = ParseTableNumber(e.TableTitle)

'---------------------------------------------------------------------------
----

Both Assert return false and first line throws a Null Object Exception.

Thanks for you help,
D


Jul 21 '05 #2

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

Similar topics

4
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event...
1
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event,...
1
by: Diotima | last post by:
I'm raising an event from a C# component and trying to catch it in a VB.NET Windows application. The VB app recognizes my custom EventArgs object and catches the event. However, when I try to read...
4
by: cashdeskmac | last post by:
I have created a control and added a few properties. One of these is an array of DateTime objects, looking like this: public DateTime MyDates { get { return theDate;} set {theDate =...
6
by: clintonG | last post by:
When I use e. in an event handler all Intellisense wants to show me is: // Event handler protected void BuildNewFileButton_Click(Object sender, EventArgs e) { // can only 'see" these properties...
6
by: Michael.Suarez | last post by:
Consider the TextBox Control. It has a KeyPress event of type KeyPressEventHandler which passes a KeyPressEventArgs to whatever method is assigned to the event. When you set e.Handled = false...
13
by: Dave | last post by:
When using the properties designer to store application wide properties how do you get this to work across a project group containing an EXE and a collection of DLLs. I'm using C#.Net 2005. I...
2
by: Brian Pelton | last post by:
I am trying to bind a textbox to the property of a property. This code works when nested property is not null, but it fails when nested is null. (It fails when SiteLine.Site is null.) The...
3
by: Tony | last post by:
Hello! One more thing assume I create an event and an object derived from the eventArgs containing some info about the event. Then create another event also with an object derived from the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.