473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net to c# eventhandler conversion help

Hi everyone, i have a vb.net program ive converted most of the code but
i know events dont translate well, the original vb.net code uses
withevents and .handles and i can't get the events in c# to work 100%

they seem to hook up ok but when the eventhandler is called from the
method its null and fails.
or maybe im reading it wrong?

anyway its quite a bit of code so i wont post but if any would help i
am willing to pay if thats ok on these boards?

regards
bryan

Mar 15 '06 #1
5 2248
c#2006user <ht*******@hotm ail.com> wrote:
Hi everyone, i have a vb.net program ive converted most of the code but
i know events dont translate well, the original vb.net code uses
withevents and .handles and i can't get the events in c# to work 100%

they seem to hook up ok but when the eventhandler is called from the
method its null and fails.
That means they're *not* hooking up ok. In my experience, most
applications only need to hook up events when you create forms to start
with.
or maybe im reading it wrong?

anyway its quite a bit of code so i wont post but if any would help i
am willing to pay if thats ok on these boards?


Don't post your whole code, but reduce it down to a minimal program
that still shows the problem. If you still don't understand why it
doesn't work, post *that* code.

See http://www.pobox.com/~skeet/csharp/complete.html for more details.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 15 '06 #2
thanks jon,

ill try.

protected ListControl mainList;
this.mainList.L eaveControl += new
dmControls.List Control.LeaveCo ntrolEventHandl er(mainList_Lea veControl);
this.mainList.S elected += new
dmControls.List Control.Selecte dEventHandler(m ainList_Selecte d);
this.mainList.S electionChanged += new
dmControls.List Control.Selecti onChangedEventH andler(mainList _SelectionChang ed);

protected delegate void
MainListLeaveCo ntrolEventHandl er(dmControls.D irection direction);
private MainListLeaveCo ntrolEventHandl er MainListLeaveCo ntrolEvent;
protected event MainListLeaveCo ntrolEventHandl er MainListLeaveCo ntrol
{
add { MainListLeaveCo ntrolEvent =
(MainListLeaveC ontrolEventHand ler)System.Dele gate.Combine(Ma inListLeaveCont rolEvent,
value); }
remove { MainListLeaveCo ntrolEvent =
(MainListLeaveC ontrolEventHand ler)System.Dele gate.Remove(Mai nListLeaveContr olEvent,
value); }
}

protected delegate void MainListSelecte dEventHandler(s tring sSelected,
object Data);
protected MainListSelecte dEventHandler MainListSelecte dEvent;
protected event MainListSelecte dEventHandler MainListSelecte d
{
add { MainListSelecte dEvent =
(MainListSelect edEventHandler) System.Delegate .Combine(MainLi stSelectedEvent ,
value); }
remove { MainListSelecte dEvent =
(MainListSelect edEventHandler) System.Delegate .Remove(MainLis tSelectedEvent,
value); }
}

protected delegate void MainListSelecti onChangedEventH andler(string
sSelected, object Item);
private MainListSelecti onChangedEventH andler
MainListSelecti onChangedEvent;
protected event MainListSelecti onChangedEventH andler
MainListSelecti onChanged
{
add { MainListSelecti onChangedEvent =
(MainListSelect ionChangedEvent Handler)System. Delegate.Combin e(MainListSelec tionChangedEven t,
value); }
remove { MainListSelecti onChangedEvent =
(MainListSelect ionChangedEvent Handler)System. Delegate.Remove (MainListSelect ionChangedEvent ,
value); }
}
private void mainList_LeaveC ontrol(Directio n direction)
{
............... ...........
}

private void mainList_Select ed(string sSelected, object Data)
{
if (MainListSelect edEvent != null)
MainListSelecte dEvent(sSelecte d, Data);
}

Mar 15 '06 #3
MainListSelecte dEvent is null when i try and call it from
mainList_Select ed.

Mar 15 '06 #4
thanks jon,

ill try.

public abstract class Page : IDisposable
{
protected ListControl mainList;

public virtual void DisplayPage(ref frmMain myForm)
{
this.mainList.L eaveControl += new
dmControls.List Control.LeaveCo ntrolEventHandl er(mainList_Lea veControl);

this.mainList.S elected += new
dmControls.List Control.Selecte dEventHandler(m ainList_Selecte d);
this.mainList.S electionChanged += new
dmControls.List Control.Selecti onChangedEventH andler(mainList _SelectionChang *ed);

}

protected delegate void
MainListLeaveCo ntrolEventHandl er(dmControls.D irection direction);
private MainListLeaveCo ntrolEventHandl er MainListLeaveCo ntrolEvent;
protected event MainListLeaveCo ntrolEventHandl er MainListLeaveCo ntrol
{
add { MainListLeaveCo ntrolEvent =
(MainListLeaveC ontrolEventHand ler)System.Dele gate.Combine(Ma inListLeaveCont *rolEvent,

value); }
remove { MainListLeaveCo ntrolEvent =
(MainListLeaveC ontrolEventHand ler)System.Dele gate.Remove(Mai nListLeaveContr *olEvent,

value); }

}
protected delegate void MainListSelecte dEventHandler(s tring sSelected,
object Data);
protected MainListSelecte dEventHandler MainListSelecte dEvent;
protected event MainListSelecte dEventHandler MainListSelecte d
{
add { MainListSelecte dEvent =
(MainListSelect edEventHandler) System.Delegate .Combine(MainLi stSelectedEvent *,

value); }
remove { MainListSelecte dEvent =
(MainListSelect edEventHandler) System.Delegate .Remove(MainLis tSelectedEvent,

value); }
}
protected delegate void MainListSelecti onChangedEventH andler(string
sSelected, object Item);
private MainListSelecti onChangedEventH andler
MainListSelecti onChangedEvent;
protected event MainListSelecti onChangedEventH andler
MainListSelecti onChanged
{
add { MainListSelecti onChangedEvent =
(MainListSelect ionChangedEvent Handler)System. Delegate.Combin e(MainListSelec *tionChangedEve nt,

value); }
remove { MainListSelecti onChangedEvent =
(MainListSelect ionChangedEvent Handler)System. Delegate.Remove (MainListSelect *ionChangedEven t,

value); }
}
private void mainList_LeaveC ontrol(Directio n direction)
{
............... ...........
}
private void mainList_Select ed(string sSelected, object Data)
{
if (MainListSelect edEvent != null)
MainListSelecte dEvent(sSelecte d, Data);
}

}

DisplayPage is then overridden and called from different type of pages
that inherit from page.

regards
bryan

Mar 15 '06 #5
oh ya its the MainListSelecte dEvent thats null when i try and call it.

any help really appreciated!

thanks.

Mar 15 '06 #6

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

Similar topics

1
5642
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases at the bottom. Hope you can help me understand the "explicit" keyword and its usage. Specifically, Is "explicit" keyword only associated with...
3
3062
by: Remco | last post by:
Hello, Serverside I'm generating a html page. There are different controls for which I want to create an eventhandler manually. Like: document.forms.TextBox1.onchange = EventHandler; document.forms.Button1.onclick = EventHandler;
0
2345
by: dominosly | last post by:
Okay, this is a rather complicated problem, so here is the short of it: I am using a custom designed user control that simply writes out a plain old html submit button to the page. When the page posts back it will randomly (I'm talking a few out of a hundred times) not catch the System.EventHandler on the submit button click. Here are...
4
4302
by: Neven Klofutar | last post by:
Hi, How can I add an even handler to a control that is not situated on the main page (it's situated in the repeater). How do I rewrite this to make it work ? Thanx, Neven ---------------------------------------------
12
4407
by: aplaxas | last post by:
Hi! "CDemo.Call" eventHandler is added to "button3.click" Event when both button1 and button2 are clicked. However, I want to add "cd.Call" only one time even though I clicked both button1 and button2. For Example, 1. Click button1 2. Click button2
4
5465
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last...
9
3071
by: Christopher Weaver | last post by:
Can anyone tell me how I could iterate through a collection of controls on a form while assigning their event handlers to another identical collection of controls on the same form. So far, thanks to another programmer, I've got this working out quite nicely for the properties: Type ctrlType = subject.GetType(); ConstructorInfo cInfo =...
0
1375
by: c#2006user | last post by:
Hi everyone, i have a vb.net program ive converted most of the code but i know events dont translate well, the original vb.net code uses withevents and .handles and i can't get the events in c# to work 100% they seem to hook up ok but when the eventhandler is called from the method its null and fails. or maybe im reading it wrong?
4
1214
by: Sascha Dietl | last post by:
hi, i wrote my own generic class based on IList that fires events, so it's just a better List<class. When my "EventedList" fires an event I don't want to take "this" as sender instead i would like to use the instance of the class that's holding my EventedList object that currently fires. Any ideas how to get this to work? thanks Sascha
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3662
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.