How to send data to controls which is in MDI Parent

S

Satish

Hi,

I am facing problem with, sending data frm mdi child to
mdi parent.

I have search Dropdown in MDI form, depend on selection,
or enter string(its like IE URL functionality) and click
search button, i am displaying Details form with all the
details. Their i have Delete button. When we click on
delete button, we have to delete the record from database
and at the same time, i have to delete record from the
drop down.

Here i have one private array list, every time depend on
search i am modifying array list and binding it to the
drop down.

I have changed drop down Modifiers to public and tried to
access from the child form. Its not accessing the
control. Any one will send how to solove this problem.

Waiting for replaies.....

Regards
Satish
 
V

Vijaye Raji

You probably didn't do a proper type-cast. If you have the control public
you should be able to access it.

Some other possible solutions:

1. Have an event on the Child form and register the parent as a listener to
the "Delete" button event.
2. Add a static method on the MDI parent's class that does the job for you
(on the currently active MDI form)

-vJ
 
S

Satish

I have written static method in MDI and tried to access
from teh chaild form. like

//this is in Child form Delete event
MDIform frm=null;
frm.Delete_ContactName();
this.Close();

this is in MDI form
public static void Delete_ContactName()
{
try
{
//array list
alContacts.Remove(cmbContact.Text.Trim());
cmbContact.Text="";
bContactFill=false;
cmbContact.DataSource=null;
cmbContact.DataSource=alContacts;
//cmbContact.SelectedIndex=0;
bContactFill=true;
}
catch{}
finally{}
}

while compiling the source its giving error that
MDIform.cmbContact denotes a 'field' where a class was
expected
 
V

Vijaye Raji

You can work around it if you know there's going to be only one MDIform per
process.

Create a new static variable in the MDIform of type MDIform and in the
constructor of MDIform, set the current instance to this variable... like
this..

public class MDIform : Form
{
...
...
private static MDIform mainForm;

/// Constructor
public MDIForm()
{
...
...
mainForm = this;
}
}

And in your static function Delete_ContactName(), use the mainForm to access
the members... like mainForm.cmbContact.Text = "";

Ok... all this aside, I think using static members for this is a bad design.
You should look into using Events and delegates. Set up an event that gets
triggered when the Delete button is clicked and listen for it from the
MainForm.

Good Luck
-vJ
 

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