I am a little unclear about what you are trying to do, but from your title it sounds like you want to influence the ListView
on
Form1 from Form2. I am assuming that Form2 is created from Form1. In your case you have two ways I can think of to do this, the first would be to create a Custom Constructor and pass the Form Instance to it or assign ownership when you show the form. The second would be to create a Custom Event on Form2 and subscribe to that in Form1.
The First Method:
in Form1 when you show Form2 use frm2.Show(this);
in Form2 when you want to call the refresh method use ((Form1)Parent).RefreshListView();
or create a Custom Constructor for Form2
Form1
public partial class Form1 : Form
{
Form2 frm2;
public Form1()
{
InitializeComponent();
frm2 = new Form2(this);
frm2.Show();
}
void frm2_RefreshList(object sender, EventArgs e)
{
RefreshListView();
}
public void RefreshListView()
{
this.listView1.BeginUpdate();
MessageBox.Show("s");//this shows! only:\ !?!?!?
listView1.Visible = false;
listView1.Height = 222;
listView1.EndUpdate();
listView1.Clear();
}
}
Form2
public partial class Form2 : Form
{
Form1 frm1;
public Form2()
{
InitializeComponent();
}
public Form2( Form frm)
{
InitializeComponent();
frm1 = (Form1)frm;
}
private void button1_Click(object sender, EventArgs e)
{
frm1.RefreshListView();
}
}
The Second Method:
Form1
public partial class Form1 : Form
{
Form2 frm2;
public Form1()
{
InitializeComponent();
frm2 = new Form2();
frm2.RefreshList += new EventHandler(frm2_RefreshList);
frm2.Show();
}
void frm2_RefreshList(object sender, EventArgs e)
{
RefreshListView();
}
public void RefreshListView()
{
this.listView1.BeginUpdate();
MessageBox.Show("s");//this shows! only:\ !?!?!?
listView1.Visible = false;
listView1.Height = 222;
listView1.EndUpdate();
listView1.Clear();
}
}
Form2
public partial class Form2 : Form
{
public event EventHandler RefreshList;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
RefreshList(this, EventArgs.Empty);
}
}