Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Listview Problem

Listview Problem

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reinier van de Wetering
    wrote on last edited by
    #1

    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.

    J H 2 Replies Last reply
    0
    • R Reinier van de Wetering

      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.

      J Offline
      J Offline
      Jon G
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • R Reinier van de Wetering

        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.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        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 the ListView 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 your ListView. The latter method is probably best. This allows you to use that form in different places and different ways. Once ShowDialog 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups