473,665 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net to c# eventhandler conversion help Please

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?
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 **tionChangedEv ent,
value); }
remove { MainListSelecti onChangedEvent =
(MainListSelect ionChangedEvent Handler)System. Delegate.Remove (MainListSelect **ionChangedEve nt,

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.

its the MainListSelecte dEvent thats null when i try and call it.

any help really appreciated!
thanks.
bryan

Mar 15 '06 #1
0 1376

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

Similar topics

2
2679
by: Sandor Heese | last post by:
Question, When using BeginInvoke (on a From to marshal to the UI thread) with the EventHandler delegate I see some strange behaviour. The problem is that I call the UpdateTextBox method with a class derived from EventArgs ( i.e. MyEventArgs) and when the BeginInvoke is called and the UpdateTextBox methode is call on the UI thread the parameter e (EventArgs) does not contain the derived MyEventArgs object but a EventArgs object. The...
0
2366
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 the details:
5
2770
by: JMWilton | last post by:
Is there a way to determine what has been added to the eventhandler list? I have code that uses += and -= to turn event handling code on and off. Apparently, it is possible to add the same event handler more than once. Documentation refers to a Delegate invocationlist...but I can't seem to access it from C#. I am looking for a way to ensure that the contents of the eventhandler list is "well known".
4
5476
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 selection and displays actual articles for display. Adding the controls and getting everything...
9
3079
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 = ctrlType.GetConstructor(Type.EmptyTypes); Control retControl = (Control)cInfo.Invoke(null);
13
9778
by: jac | last post by:
Hae, I have a windows form with a ComboBox an other things. On that combobox I have an eventhandler on de selectedindexchanged. But somewhere in my code want to do excecute the same code that is writen in the eventhandler. Is it posible to call that eventhandler from the code (not from a real selectedindexchanged on the form). So, I don't have to call that code twice.
2
1459
by: mawi | last post by:
Hi there, When removing page children controls created dynamically not in last-to-first order, the close button of the last control looses its event wiring, even though the handler is rewired on each postback. It needs one postback roundtrip to "get it back". Form has an "add panel" button. Using it I dynamically add 3 panels with a remove button on each, A B C, to the page.
2
3333
by: i676373 | last post by:
Hi, I have a instance of Button, button1. button1.Click event is already associated with some unknown event handler, e.g. ======= button1.Click += new EventHandler(btn_click1); button1.Click += new EventHandler(btn_click2); How can I know the the list of eventhandler which is associated with
5
2251
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? 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...
0
8438
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.