when user clicks on this event ,CR shows the form ,but when you close this form and wanna
reopen it ,below error occurs
<< ObjcetDisposedException was unhandled "cannot access a disposed object." >>
where shall I get the instace of the object (CR) ?
pay attention that I used the FormClosedEventHandler .
this is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Mini_dbms
{
public partial class Form1 : Form
{
CreateDB.Form2 CR = new CreateDB.Form2();
public Form1()
{
InitializeComponent();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void CreateToolStripMenuItem_Click(object sender, EventArgs e)
{
//CreateDB.Form2 CR = new CreateDB.Form2();
CR.Show(); // error in here while reopenig it<< ObjcetDisposedException was unhandled "cannot access a disposed object." >>
}
private void Main_Load(object sender, EventArgs e)
{
CR.FormClosed += new FormClosedEventHandler(CR_FormClosed);
}
void CR_FormClosed(object sender, FormClosedEventArgs e)
{
if (CR.flag == 1)
{
toolStripStatusLabel1.Text = "successfully created!";
}
else if(CR.flag==2)
{
toolStripStatusLabel1.Text = "Creation failed !";
}
}
}
}
Raaj KumarPosted Feb 17, 2010, 8:27 AM
It seems the form object CR. is disposed after it is closed. So you could do something like instead of instantiating outside the CreateToolStripMenuItem_Click method, you could create it inside the method and make this CR just declared just like this.
CreateDB.Form2 CR
So each time you click new object is been created which wont give any error
Regards,
Raaj