?
Solved

Casting between two Events...

Posted on 2007-08-01
13
Medium Priority
?
215 Views
Last Modified: 2010-04-15
Hi,
In first class there is an Event (of type DataGridCommandEventArgs ) :
        void dataGrid_ItemCommand(object source, DataGridCommandEventArgs e)
           {
                 this.User= Convert.ToInt32(e.Item.Cells[0].Text);
                 UserData = GetUsersData(this.User);
                 
                  Test t = new Test();
                  t.GoTo_Next(source, e);
           }
In second class there is Event :
          public void GoTo_Next(object sender, CommandEventArgs e)
            {
                Update((Dictionary<string, object>)e.CommandArgument);
             }
         
I get an error :
     Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'.

(2 - is an item which comes from DataGridCommandEventArgs e.)

Is it possible to cast?
Thanks


0
Comment
Question by:udir
  • 7
  • 6
13 Comments
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19607624
Hi,

so you want to pass the data you've taken here:

 this.User= Convert.ToInt32(e.Item.Cells[0].Text);
                 UserData = GetUsersData(this.User);

and pass it to the other class via the event?
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19607644
try passing the commandArgument from the DataGridCommandEventArgs

e.g.

t.GoTo_Next(source, e.CommandArgument
0
 
LVL 11

Accepted Solution

by:
Babycorn-Starfish earned 2000 total points
ID: 19607678
Sorry,

i dont think that will work. You can pass the e.CommandArgument but within your second class you would need to extract the string, object pair in a manner similar to how you did it in the first class.

If you don't need to know the sender you could pass it like this:

object[] o = new object[]{this.User, UserData};

t.GoTo_Next(o, null);

and then at the other end

String user = (string)o[0];
object data = o[1];
Update(user, data);


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:udir
ID: 19607710
Hi guys,
I'm a little confused (probably u to, becuase it is just a little hard to explain (:

I don't need to pass data, i just need that :
e.CommandArgument = 0
and e.CommandName = "Next"
(I think...)
becuase when i call it (fire it) from the original event, i see those argument.
In general, what i'm trying to do is call an event (like it was a function) from another event.
Any idea?

0
 
LVL 1

Author Comment

by:udir
ID: 19607715
Oh sorry , no guys , only Babycorn-Starfish   -:)
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19607844
lol, yeah confused.

Okay, what are you trying to achieve. Don't worry about explaining it badly i'll ask you more q's rather than abandon you.

From what i see above
the first event handler takes some info out of the DataGridCommandEventArgs instance 'e', then it looks like you want to call another method via an event in another class and pass the same data you had in the first class, is this right?
0
 
LVL 1

Author Comment

by:udir
ID: 19607896
First - thanks!
this is right execept - passing data to the next event.
I just need (again, i think...) to "simulate" the call of the second event (like i used to call it from the original event.
When i call it from the original event, the 'e' looks like that :
e.CommandArgument = 0
and e.CommandName = "Next"
Now, i'm calling the event from complitally different event (DataGridCommandEventArgs)
and this is the problem.

0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19607940
okay :) 2/3 more q's

what is it that you expect to happen when you call the second event?

what does Update do in the second event.

From the way it looks, it seems calling Update is the main purpose of the second event handler - it's the only thing in there.  Is the Update method in class 2 visible to class 1?
0
 
LVL 1

Author Comment

by:udir
ID: 19608151
sorry, there are several problems with database (i can't do anything for now)
I'l come back when i'l fix it....
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19608172
no probs :)
0
 
LVL 1

Author Comment

by:udir
ID: 19615141
Hi again Babycorn-Starfish,
Well, dataBase ok and i succeed with the problem (completly different solution)
Anyway, now i have another problem, but i think it will be fair to give u the points for this que,
and open a new que - aim to u.
What do u say ?
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19615994
only give points if i helped you arrive at your solution!!

I don't mind really :)

Probably best to open your new question to everyone, lots of smart people here.
0
 
LVL 1

Author Comment

by:udir
ID: 19617126
Well, i succedd also with my next problem  (:
Thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question