User Controls Help

N

nntp.microsoft.com

I have been struggling with this for too long now, an desperately need help.
I'm an asp.net programmer, but am working on a windows form for this app. I
have 1 form and 2 user controls, Say UC(A) and UC(B). UC(A) has a datagrid,
UC(B) has a ListBox. When I click on the Datagridrow in UC(A) , the
Listbox in UC(B) should Update based upon an ID in the Datagrid, but It
wont. I have Tried using RaiseEvents first, then I tried just making a
Public Method, and then I tried a Public Property. The code in UC(B) is
Fired properly, and the Dataset is retreived from my DataClass, but When I
tell my listbox what the data source is, it wont rebind or redraw or
something. I also tried the declaring a public event in UC(A), and then
Delare UC(A) in UC(B) and setting a method to handle it. But that does not
work It fires the event, but nothing at all happens in UC(B).

What am I missing.

Tom Callahan
 
B

Bruce Wood

I have been struggling with this for too long now, an desperately need help.
I'm an asp.net programmer, but am working on a windows form for this app. I
have 1 form and 2 user controls, Say UC(A) and UC(B). UC(A) has a datagrid,
UC(B) has a ListBox. When I click on the Datagridrow in UC(A) , the
Listbox in UC(B) should Update based upon an ID in the Datagrid, but It
wont. I have Tried using RaiseEvents first, then I tried just making a
Public Method, and then I tried a Public Property. The code in UC(B) is
Fired properly, and the Dataset is retreived from my DataClass, but When I
tell my listbox what the data source is, it wont rebind or redraw or
something. I also tried the declaring a public event in UC(A), and then
Delare UC(A) in UC(B) and setting a method to handle it. But that does not
work It fires the event, but nothing at all happens in UC(B).

What am I missing.

Well, you would need to post some code for us to see exactly what is
going wrong.

However, I would start by architecting the solution this way: UC(A)
declares a public event (which you did). UC(B) exposes a public get/
set property for the ID that it needs in order to show what it needs
to show. (If it needs more than an ID, such as say a row in a DataSet,
it could expose a property to accept the entire row.)

Then, in your enclosing form, subscribe to UC(A)'s event, and in the
event handling method get the ID (or whatever information) from UC(A)
via some public property that you define, and then use UC(B)'s public
property to set the info in UC(B). In other words, the enclosing form
acts as the go-between: it reacts to the event from UC(A) and then
feeds UC(B) whatever information it needs.

This way neither user control needs to know about the other. It's a
bit more code to write, but it's way easier to debug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top