Listview Problem
-
How can i load values into a listview from a event that is on another form than the listview. The listview is on a control on my main form, but I open a new form to change some values and when i click on save it should change the listview on the Main form. It will also be fine to load the values when the child form closes, but i can't get that to work either. I tried to run a function from the child form but nothing happens. thnxs.
-
How can i load values into a listview from a event that is on another form than the listview. The listview is on a control on my main form, but I open a new form to change some values and when i click on save it should change the listview on the Main form. It will also be fine to load the values when the child form closes, but i can't get that to work either. I tried to run a function from the child form but nothing happens. thnxs.
Probably not the best way to do this, but you could always make your parent listview "public static", and directly assign the values from your child. A major problem with this is, your main form would probably need to be static as well. You could also store all the data in a class object, and return the object back to the main form, and extract all the data from the object. Just a few suggestions. I might be totally wrong.
-
How can i load values into a listview from a event that is on another form than the listview. The listview is on a control on my main form, but I open a new form to change some values and when i click on save it should change the listview on the Main form. It will also be fine to load the values when the child form closes, but i can't get that to work either. I tried to run a function from the child form but nothing happens. thnxs.
A better way than making it static (you'll run into all kinds of problems with this approach, especially if you want to use the designer after making those suggested changes) is to either pass a reference to the
ListView
to the form you open, or make a public property that gets theListView
on the first form and pass a reference to the first form into the second form (probably better if you ever want to do similar things in the future), or - finally - provide a way to get the data from the second form inside the first form and then have your first form add the data to yourListView
. The latter method is probably best. This allows you to use that form in different places and different ways. OnceShowDialog
returns, you can grab that data (in a collection, list, array, a single property or properties, or whatever) and use it however you want.Microsoft MVP, Visual C# My Articles