Click here to Skip to main content
16,011,444 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
1)I have list view and [add] button on form1
2)Once I clicket on [add] button, it will open form2
3)On form2, I am inserting the value in SQL table which is accessed for loading listview on form1.
4)write insert query on form2_closed
5)could not able to inserted value in form1 list box

What I have tried:

List box is not refreshing properly,
Posted
Updated 2-May-16 5:49am
Comments
Richard MacCutchan 2-May-16 11:03am    
Your code is not correct.
OriginalGriff 2-May-16 11:45am    
Without the relevant code fragments, there isn't a lot we can do...
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Try this,
check the inline comments

Form1
C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } 
       

        // Method to refresh the list view or any
        public  void RefreshListView()
        {
            // your code to refresh the list
        }

       // button click event to  open the form2
        private void buttonOpenForm2_Click(object sender, EventArgs e)
        {
            Form2 obj = new Form2();
            obj.MyParent = this;  // Initialise the Form2's MyParent property with this current object 
            obj.Show();
        }
    }


Form2
C#
public partial class Form2 : Form
   {
       public Form2()
       {
           InitializeComponent();
       }

       public Form MyParent { get; set; }  // Property to Get the object of parent form

       private void buttonClose_Click(object sender, EventArgs e)
       {
           MyParent.GetType().GetMethod("RefreshListView").Invoke(MyParent, null);  // Invoke the parent form RefreshLIstView Method using Reflection.
       }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900