473,418 Members | 2,020 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,418 software developers and data experts.

How to check if event is loaded?

I'm using a DataGrid and have assigned

this.DataSourceChanged += new EventHandler( DataGrid_DataSourceChanged
);

This works fine but there is one case where it doesn't. How can I
check if DataSourceChanged has anything assigned. I can add it to the
watch because it says it needs to be on the left side of a -= or +=.

Thanks,
Brett

Sep 1 '06 #1
14 7393
Unless you "own" the class publichsing the event, there is no robust
way of doing this. However, if you have subscribed to the event (and it
didn't error) then chances are that it worked fine and the
DataSourceChanged backer has (at least) 1 delegate.

Can you give any more details on the one case where it doesn't work? It
is more likely to be specific to your usage / expectations.

Marc

Sep 2 '06 #2
Unless you "own" the class publichsing the event

What do you mean by own the class? I've created all the code involved.

The event isn't firing in the one case. I know because a breakpoint in
the delegated method is never hit in the one case. I'd like to give
details but it would require lots of explaining. If there is just a
way to check the invocation list for the one event, that would be a
good start.

Thanks,
Brett

Sep 2 '06 #3
I mean DataGrid, so no: you don't. And no there isn't.

Sep 2 '06 #4
You could always add a public method call that returned the delegate list to
the class the defines the event. You could then examine the delegates to see
if the one you think ought to be there really is.

public Delegate[] GetlList()
{
if ( YourEventNameHere != null )
return YourEventNameHere.GetInvocationList();
return new Delegate[0]; // empty list
}
"Brett Romero" <ac*****@cygen.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>Unless you "own" the class publichsing the event

What do you mean by own the class? I've created all the code involved.

The event isn't firing in the one case. I know because a breakpoint in
the delegated method is never hit in the one case. I'd like to give
details but it would require lots of explaining. If there is just a
way to check the invocation list for the one event, that would be a
good start.

Thanks,
Brett

Sep 3 '06 #5

David Levine wrote:
You could always add a public method call that returned the delegate list to
the class the defines the event. You could then examine the delegates to see
if the one you think ought to be there really is.

public Delegate[] GetlList()
{
if ( YourEventNameHere != null )
return YourEventNameHere.GetInvocationList();
return new Delegate[0]; // empty list
}
DataGrid.DataSourceChanged doesn't have a GetInvocationList().

Thanks,
Brett

Sep 3 '06 #6
You said that you wrote the event but I gather that is not the case.

If it's an event then either it has a GetInvocationList() method or they
defined their own backing store for the delegates. In either case it is only
directly accessible to the class that defines the event, not to subscribers
to the event. But you can use reflection to access those hidden fields. I
suggest using reflector to look at how the event was implemented. You may
able to use reflection to access the delegate list.

"Brett Romero" <ac*****@cygen.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>
David Levine wrote:
>You could always add a public method call that returned the delegate list
to
the class the defines the event. You could then examine the delegates to
see
if the one you think ought to be there really is.

public Delegate[] GetlList()
{
if ( YourEventNameHere != null )
return YourEventNameHere.GetInvocationList();
return new Delegate[0]; // empty list
}

DataGrid.DataSourceChanged doesn't have a GetInvocationList().

Thanks,
Brett

Sep 3 '06 #7

David Levine wrote:
You said that you wrote the event but I gather that is not the case.

If it's an event then either it has a GetInvocationList() method or they
defined their own backing store for the delegates. In either case it is only
directly accessible to the class that defines the event, not to subscribers
to the event. But you can use reflection to access those hidden fields. I
suggest using reflector to look at how the event was implemented. You may
able to use reflection to access the delegate list.
I inherited DataGrid for my own DataGrid. DataSourceChanged is an
event that comes from the base (DataGrid). I only created a method in
my datagrid to delegate the event to. I didn't write the handler.

I've added the datagrid in question to my watches. I can see
InvocationList deep down inside the datagrid. However, the only thing
ever there is DoubleClick. So I still don't see a route to figure out
if the DataSourceChanged event is wired up according to the datagrid.

Thanks,
Brett

Sep 3 '06 #8
Let's try a different approach...you said previously that you subscribed to
the DataSourceChanged event. Check the invocation list of that event
immediately to ensure yourself that you did indeed subscribe to it. Now, why
would you think that at some point later it is not subscribed? Are you sure
that the conditions that should cause the event to get fired have actually
occurred?

"Brett Romero" <ac*****@cygen.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
>
David Levine wrote:
>You said that you wrote the event but I gather that is not the case.

If it's an event then either it has a GetInvocationList() method or they
defined their own backing store for the delegates. In either case it is
only
directly accessible to the class that defines the event, not to
subscribers
to the event. But you can use reflection to access those hidden fields. I
suggest using reflector to look at how the event was implemented. You may
able to use reflection to access the delegate list.

I inherited DataGrid for my own DataGrid. DataSourceChanged is an
event that comes from the base (DataGrid). I only created a method in
my datagrid to delegate the event to. I didn't write the handler.

I've added the datagrid in question to my watches. I can see
InvocationList deep down inside the datagrid. However, the only thing
ever there is DoubleClick. So I still don't see a route to figure out
if the DataSourceChanged event is wired up according to the datagrid.

Thanks,
Brett

Sep 4 '06 #9

David Levine wrote:
Let's try a different approach...you said previously that you subscribed to
the DataSourceChanged event. Check the invocation list of that event
immediately to ensure yourself that you did indeed subscribe to it. Now, why
would you think that at some point later it is not subscribed? Are you sure
that the conditions that should cause the event to get fired have actually
occurred?
At the point I'm checking on the subscriber side, here is what I do:

MyDataGrid.DataSource = null;
MyDataGrid.DataSource = myDataTable;

I do that on purpose to make sure the source is not null and ensure
DataSourceChanged() has to fire. Inside of MyDataGrid, I override the
datasource and assign the value coming in to base.datasource. After
that assignment, DataSourceChanged() fires. It all works fine except
for this one condition on the above code. I have a breakpoint inside
of MyDataGrid.DataSourceChanged() method as well. I'll go through the
above code a few times and all works fine. Then I hit a point at which
it doesn't fire my breakpoint inside of DataSourceChanged. Hope that
helps more.

Now, how exactly do I get at InvocationList() for DataSourceChanged?
Where do I check that exactly? Are you saying at some place I break
and check MyDataGrid.InvocationList()? Because if you are, that method
doesn't exist there. It's buried down inside of base, base on the
watch list for my custom datagrid.

Thanks,
Brett

Sep 4 '06 #10
And you are sure that myDataTable isn't null?
Are there any threads involved? (since the DataGrid is a winform
control, it could create issues if you are changing the property on the
wrong thread).

Inside the DataSource setter, it checks:

if ((this.dataSource == null) || !this.dataSource.Equals(value))
{
if (((value == null) || (value == Convert.DBNull)) &&
((this.DataMember != null) && (this.DataMember.Length != 0)))

{blah}

if second "if" returns true, ir runs simple code (and doesn't fire
event); if it returns false (real data source) it calls:

this.EnforceValidDataMember(value); // only if value not null
this.ResetParentRows();
this.Set_ListManager(value, this.DataMember, false);

It is this last that fires the event, but it is very complex. Could any
of this explain your issue? Is the data really valid? Is it non-null?
On the right thread? etc.

Marc

Sep 4 '06 #11

Marc Gravell wrote:
And you are sure that myDataTable isn't null?
Are there any threads involved? (since the DataGrid is a winform
control, it could create issues if you are changing the property on the
wrong thread).

Inside the DataSource setter, it checks:

if ((this.dataSource == null) || !this.dataSource.Equals(value))
{
if (((value == null) || (value == Convert.DBNull)) &&
((this.DataMember != null) && (this.DataMember.Length != 0)))

{blah}

if second "if" returns true, ir runs simple code (and doesn't fire
event); if it returns false (real data source) it calls:

this.EnforceValidDataMember(value); // only if value not null
this.ResetParentRows();
this.Set_ListManager(value, this.DataMember, false);

It is this last that fires the event, but it is very complex. Could any
of this explain your issue? Is the data really valid? Is it non-null?
On the right thread? etc.

Marc
Marc,

First, where are you getting all of these details about how the
datasource operates?

The data is there in myDataTable. I see a table name when mousing over
it and when looking at the data debug view (clicking the magnifying
class), I see all of the columns and rows of data. This is a single
threaded app.

this.datasource is null because of the first null assignment I do.
value is valid with data and the two are different. All of the
conditions are correct to trigger the event. DataMember is not being
used.

It's to much explaining without walking through the code but here's a
little info on the overall picture:
The form in question (FormA) is in an MDI app. Double clicking a row
in the datagrid opens FormB in the MDI. The user can make an update on
FormB and click an update button. This fires an event that FormA is
listening for and reassigns the datasource of the grid on FormA.

When the app initially loads, FormA fills with data automatically.
Everything works fine. However, when the user closes FormA (not the
app) and reopens via the toolbar new button, the update event fires but
not the DataSourceChanged event. DataSourceChanged does fire however
for other events (for both paths to FormA). There is no difference
here. Loading FormA via new app initialization or clicking the new
button uses the same method (ShellForm.MethodA) to load the form. But,
getting to FormA in those two ways is the only difference I have found,
which doesn't say anything since nothing happens to FormA until you are
in ShellForm.MethodA.

Thanks,
Brett

Sep 4 '06 #12
First, where are you getting all of these details about how the
datasource operates?
Reflector; quite simply one of the most powerful and useful .Net tools I
know of (outside of the framework itself):

http://www.aisto.com/roeder/dotnet/

Reading your description, it sounds like everything should work. I still
strongly suspect that there is a gotcha in your code somewhere; I can only
really suggest trying to reproduce it in a simple example. Sorry, but I'm
out of ideas without some source code.

Marc
Sep 4 '06 #13
I see beyond what I'm doing in DataSource into the base.DataSource,
which you posted above. However, I can't step into it to see what
conditions are being met. Do you have any suggestions?

Here's my datasource:

public virtual Object DataSource
{
get
{
return base.DataSource;
}
set
{
base.DataSource = value;
//base.DataSource = value
if( ResultsCountChanged != null && base.DataSource !=
null )
ResultsCountChanged( new
CustomDataGridResultCountEventArgs( ( ( DataTable )this.DataSource
).DefaultView.Count ) );
}
}

Thanks,
Brett

Sep 5 '06 #14
I think I found something in the datagrid:

base.Events.parent.events.head.next.next.handler.M ethod

it's value is

Void CustomDataGrid_DataSourceChanged(System.Object, SystemEventArgs)

I have it in the watch. There are a large number of items to view on
this. However, I'm not sure what exactly in there I should look for.
Any suggestions?

Thanks,
Brett

Sep 5 '06 #15

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

Similar topics

1
by: Adam Ratcliffe | last post by:
I'm trying to come up with a solution for detecting when an image, loaded by a script, has completely loaded. The Image.onload event is fired after the image has loaded in Firefox but before...
2
by: David N | last post by:
Hi All, The OnLoad() event is invoked automatically when a form is being loaded. Do we have another event that is invoked automatically after a form has completed loading? Thanks.
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
4
by: Jiho Han | last post by:
What is the best way to check whether the page is simply a postback or the form has been submit with the intention of doing something? In the olden days, I used to check for a form field name...
5
by: Engineerik | last post by:
I have a login form which I want to display with the showdialog method. When I do that the event handler for the load event does not run. If I use the show method the load event handler runs...
8
by: VB Programmer | last post by:
I am using a FileUpload control (ASP.NET 2.0). How do I check the length of the file in bytes BEFORE I let them upload it? I believe my code checks now AFTER... If...
2
by: cottonj | last post by:
is there anyway to force an event, like mouseover? I have a page that loads, and due to some complex js code (not mine) it fails to write labels to tabs until the user does a mouseover on the...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
5
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.