Writing an event handler in VB.NET - too much hard work!

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
OK< maybe I've been spoiled, but in C#, if I want to handle the MyDataTableRowChanging event, I can write in the form's constructor:

VB.NET:
  this.MyDataSet.MyDataTable.MyRowChanging +=

A tooltip appears at this point, suggesting something like:

new MyRowChangeEventHandler( [PRESS TAB TO INSERT]

I press Tab


at this point, another suggestion appears:

My_RowChange [PRESS TAB TO INSERT]

I press Tab, and a new sub is created to handle this event..

Our code in the constructor ends up something like:

VB.NET:
  this.MyDataSet.MyDataTable.MyRowChanging += new MyRowChangeEventHandler(My_RowChange)

}

public void My_RowChange(Object sender, RowChangeEventArgs e){
  //TODO: add your event handler code here
}


How do we do this in VB? I want the IDE to write the signature for me, and put in the handler..



Update: ok, so here's a way I deem rather lame, but I cant find a significantly easier way:

VB.NET:
Public Form blah

  Private WithEvents x As MyDataSet.MyDataTable = Me.MyDataSet.MyDataTable

  Private xy() Handles x.MyRowChanging

Then with the compiler error:

Method 'Private Sub xy()' cannot handle Event 'Public Event MyRowChanging(sender As Object, e As App1.MyDataSet.MyDataTable.ContactRowChangeEvent)' because they do not have the same signature.

copy the bold bit, and paste it in as the handler.

This just strikes me as being a mess. Maybe I could AddHandler() it, but why is the IDE so unhelpful?
 
Last edited:
Adding handlers at runtime isnt exactly related to the question I'm asking, I'm afraid. My question is more based in what we can do to get the IDE to actually be helpful, like it is in C#. I just dont think the IDE can do it, there are no snippets about it, and no offerings of help when writing it..
 
C# 2005 seems pretty old school too

(Don't pay any attention to the fact that I use VS 2003 still....)
 
cjard;62020but why is the IDE so unhelpful?[/QUOTE said:
But in vb.net we have two comboboxes on top of the code window and from the right box we can select the events and most of the times that helps a lot which is still not in c#.
 
In this case, because I want to attach to an event that is exported by a member of a class instance, I cannot do it.

i.e. your ComboBoxes will show me:

[MyDataSet|V|] [MyDataSet Events...]

But I'm trying to access an event of myDataSet.MyDataTable


I cant write that in a handles clause.. and it doesnt show in the combo, because it is buried inside the DataSet.

C#, in those combos, only shows us what we already have, because the Intellisense allows us ultimate flexibility of what we dont have..

In VB. the combos show us what we dont have, and the Intellisense is restricted..

Overall, VBN is more restrictive, and its a nuisance
 
Back
Top