Search code examples
c#formsresourcesobjectdisposedexception

Accessing a disposed object (form) in C#?


I have two forms, once I double click a row on a dataGridView of one form, the other form opens up with information about that particular row. But after I close the second form and double click on another row in my dataGridView to open the same form but with different information regarding the newly clicked row, "Cannot access a disposed object.", "Make sure you have not released a resource before attempting to use it" errors come up. How do I reuse the second form again??


Solution

  • My guess is you're creating one SecondForm (whatever you called it) object for this second form and calling ShowDialog() or some such on it. When you close it it's being disposed. What you likely need to do is create a new SecondForm object each time you handle the double click event.