Refreshing a Datagrid from another form.

  • Thread starter Thread starter SePp
  • Start date Start date
S

SePp

Hi all.

I want to refresh a Datagrid from another form.

For Example I have a Datagrid in that I want to edit data. The user
has the ability to press a button to change these data.
A new Form opens and the user changes the data. After that he saves
the changes and the current form is closing and the old form with the
datagrid gets the focus again.

At the point the user is saving the data I want to refresh the data in
the form with the datagrid.

Could you please tell me a way to do that? Thank you very much.

Kind regards,
SePp
 
Hi,


You can make the grid public (not the best option) so that the other form
has access to it.

A better approach though is to make a public method available which in turn
would update the grid (and any other controls in the form)
 
Hi,

You can make the grid public (not the best option) so that the other form
has access to it.

A better approach though is to make a public method available which in turn
would update the grid (and any other controls in the form)

--
Ignacio Machinhttp://www.laceupsolutions.com










- Show quoted text -


Hm I can't find a way to get it working.
Here an example:

Form1:

Has a combobox I get these data from an OracleDatabase:

something like:

private void load_combobox_1()
{
OracleDataAdapter cmd = new OracleDataAdapter("select *
from ", conn);
cmd.TableMappings.Add("Table", "TABLE1");
DataSet ds = new DataSet("TABLE1");
cmd.Fill(ds);
comboBox_1.DataSource = ds.Tables["TABLE1"];
comboBox_1.ValueMember = "Col1";
comboBox_1.DisplayMember = "col2";
comboBox_1.SelectedIndex = -1;
}


To reload that i have a method:

public void reload_information()
{
load_combobox_1();
}




Now I am opening Form2

Form2 bd = new Form2;
bd.Show();


And atFormClose I want to reload the information in the combobox at
form1:

reload_information();


Here are the way I tried it:

Form1 bd = new Form1()
bd.reload_information();
But this can't work because I generate a new object.


So the big question for me is how do I get the actual Object from
Form1 to reload the information at it.
Something with this. ???


Thank you very much in advance for your information!!!!

Kind regards,
SePp
 
Hi,

You need to pass a reference of Form1 to form2

//assuming this is form1
Form2 bd = new Form2( this);
bd.Show();


Then in form2 you do:
Form1 form1;
public Form2( Form1 form){ this.form1 = form;}

In the onClose event of form2 you do:

if ( form1!= null)
form1.load_combobox_1();


--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Hi,

You can make the grid public (not the best option) so that the other form
has access to it.

A better approach though is to make a public method available which in
turn
would update the grid (and any other controls in the form)

--
Ignacio Machinhttp://www.laceupsolutions.com










- Show quoted text -


Hm I can't find a way to get it working.
Here an example:

Form1:

Has a combobox I get these data from an OracleDatabase:

something like:

private void load_combobox_1()
{
OracleDataAdapter cmd = new OracleDataAdapter("select *
from ", conn);
cmd.TableMappings.Add("Table", "TABLE1");
DataSet ds = new DataSet("TABLE1");
cmd.Fill(ds);
comboBox_1.DataSource = ds.Tables["TABLE1"];
comboBox_1.ValueMember = "Col1";
comboBox_1.DisplayMember = "col2";
comboBox_1.SelectedIndex = -1;
}


To reload that i have a method:

public void reload_information()
{
load_combobox_1();
}




Now I am opening Form2

Form2 bd = new Form2;
bd.Show();


And atFormClose I want to reload the information in the combobox at
form1:

reload_information();


Here are the way I tried it:

Form1 bd = new Form1()
bd.reload_information();
But this can't work because I generate a new object.


So the big question for me is how do I get the actual Object from
Form1 to reload the information at it.
Something with this. ???


Thank you very much in advance for your information!!!!

Kind regards,
SePp
 
Hi,

You need to pass a reference of Form1 to form2

//assuming this is form1
Form2 bd = new Form2( this);
bd.Show();

Then in form2 you do:
Form1 form1;
public Form2( Form1 form){ this.form1 = form;}

In the onClose event of form2 you do:

if ( form1!= null)
  form1.load_combobox_1();

--
Ignacio Machinhttp://www.laceupsolutions.com

You can make the grid public (not the best option) so that the other form
has access to it.
A better approach though is to make a public method available which in
turn
would update the grid (and any other controls in the form)
- Show quoted text -

Hm I can't find a way to get it working.
Here an  example:

Form1:

Has a combobox I get these data from an OracleDatabase:

something like:

        private void load_combobox_1()
        {
            OracleDataAdapter cmd = new OracleDataAdapter("select  *
from ", conn);
            cmd.TableMappings.Add("Table", "TABLE1");
            DataSet ds = new DataSet("TABLE1");
            cmd.Fill(ds);
            comboBox_1.DataSource = ds.Tables["TABLE1"];
            comboBox_1.ValueMember = "Col1";
            comboBox_1.DisplayMember = "col2";
            comboBox_1.SelectedIndex = -1;
        }

To reload that i have a method:

public void reload_information()
{
load_combobox_1();

}

Now I am opening Form2

Form2 bd = new Form2;
bd.Show();

And atFormClose I want to reload the information in the combobox at
form1:

reload_information();

Here are the way I tried it:

Form1 bd = new Form1()
bd.reload_information();
But this can't work because I generate a new object.

So the big question for me is how do I get the actual Object from
Form1 to reload the information at it.
Something with this. ???

Thank you very much in advance for your information!!!!

Kind regards,SePp- Hide quoted text -

- Show quoted text -

Hi Ignacio Machin

A lot of thanks to you! It's very much appreciated!!! I searched for a
solution for a long time!!!!!!

Kind regards,
SePp
 

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

Back
Top