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

How to fix "Events does not exist in current context." error in?

I have a VB code as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Shared ReadOnly RowClickedEventKey As Object = New Object
  2.  
  3. Public Custom Event RowClicked As EventHandler(Of GridViewRowClickedEventArgs)
  4.  
  5. AddHandler(ByVal value As EventHandler(Of GridViewRowClickedEventArgs))
  6.     Events.AddHandler(RowClickedEventKey, value)
  7. End AddHandler
  8.  
  9. RemoveHandler(ByVal value As EventHandler(Of GridViewRowClickedEventArgs))
  10.     Events.RemoveHandler(RowClickedEventKey, value)
  11. End RemoveHandler
  12.  
  13. RaiseEvent(ByVal sender As Object, ByVal e As GridViewRowClickedEventArgs)
  14.                 Dim ev As EventHandler(Of GridViewRowClickedEventArgs) = TryCast(Events(RowClickedEventKey), EventHandler(Of GridViewRowClickedEventArgs))
  15.                 If ev IsNot Nothing Then
  16.                     ev(sender, e)
  17.                 End If
  18. End RaiseEvent
  19.  
  20. End Event
  21. Protected Overridable Sub OnRowClicked(ByVal e As GridViewRowClickedEventArgs)
  22.     RaiseEvent RowClicked(Me, e)
  23. End Sub
  24.  
This works flawlessly in VB, but when I translate to C Sharp:

Expand|Select|Wrap|Line Numbers
  1.         public event EventHandler<GridViewRowClickedEventArgs> RowClicked
  2.         {
  3.             add { Events.AddHandler(RowClickedEventKey, value); }
  4.  
  5.             remove { Events.RemoveHandler(RowClickedEventKey, value); }
  6.  
  7.         }
  8.         protected virtual void OnRowClicked(GridViewRowClickedEventArgs e, Object sender)
  9.         {
  10.             EventHandler<GridViewRowClickedEventArgs> ev = Events(RowClickedEventKey) as EventHandler<GridViewRowClickedEventArgs>;
  11.             if (ev != null)
  12.             {
  13.                 ev(sender, e);
  14.             }
  15.         }
  16.  
in "Events(RowClickedEventKey)", it complains "Events does not exist in current context. What should I write the raise event part in C Sharp?

Thanks.
Feb 10 '11 #1
1 3049
Maybe you should read more closely into the compiler output. 'Events' does not exist, it is NOT a function. I'm not sure what you are trying to do but this is a common generic error, the function simply doesn't exist in the context at which you are trying to use it in.
Feb 12 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: User | last post by:
Hi, How better is to implement my own event (and calling my raiseevent) instead of calling a function. I receive a lot of data via winsock control, should I raise my event when receiving all...
2
by: Mauricio Rendon | last post by:
Hi, If I have a Label in a Form and need to raise the MouseUp event on the label to the Form ( Parent Control ), What must I do ? Thanks !!!
5
by: Waleed AlRashoud | last post by:
Hi, I hope u can help me I asked this question before but I didn't explain it very well. Let say I hvae a thread 'A', creates object 'O', and start thread 'B' to do some work on 'O', OK? I...
2
by: Nikhil Patel | last post by:
Hi all, How can I raise the Click event of the LinkButton server control in Javascript? Thanks.
0
by: Mike | last post by:
I have a asp.net (vb.net) web app that calls a VB.NET class. This class has a raise Event in it. - raised event getStuff I can't call the raised Event getStuff. Can i not call or execute a raised...
3
by: moondaddy | last post by:
I wrote my own List class which I use to bind to list controls. this class inherits CollectionBase and implements IBindingList. This class contains a list of business classes such as customers...
2
by: tony | last post by:
Hello !! I have a question about event. This small program below is taken from the internet and I wonder if there are any advantage to use this Onxxx in this case it's OnEventSeven instead of...
1
by: John Dann | last post by:
VB.Net 2005: I have a class that performs some functions and then needs to update some labels on the main form (from which it is called) with several pieces of information, some text, some...
0
by: Silver Oak | last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was created dynamically using iTemplate. I would like to have multi-row editing capability on the DataGrid. I'm trying to...
3
by: Rastra | last post by:
Hi I have been trying to raise an event in the user control. The problem is I always get null reference in the event and my event never gets fired. Can someone help me? The Code I have written is as...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.