A
Adam
Hello,
I am still learning C#, so please bear with me.
I have a two Form, from first I open second form with datagrid. When I
Dispose datagrid second time I get a ObjectDisposedException.
In first (main) form I have a button with code under onclick event:
temp_n = this.Text;
this.Text = string.Empty;
Form1 frm1 = new Form1;
frm1.ShowDialog();
frm1.Dispose();
this.Text = temp_n;
and in second form:
private void Form1_Load(object sender, EventArgs e)
{
ceCmd = Global.DatabaseConnection.CreateCommand();
ceCmd.CommandText = "select col1,col2 from table";
ceCmd.CommandType = CommandType.Text;
ceResSet = ceCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
dataGrid1.DataSource = ceResSet;
}
and
private void Form1_Closed(object sender, EventArgs e)
{
if (ceResSet != null)
{
ceResSet.Close();
ceResSet.Dispose();
}
if (dataGrid1 != null) dataGrid1.Dispose();
}
and when I twice opened and closed second Form i get a
ObjectDisposedException on
"if (dataGrid1 != null) dataGrid1.Dispose();"
it's strange to me because when i put button on second form and add event:
private void Button_Click(object sender, EventArgs e)
{
if (ceResSet != null)
{
ceResSet.Close();
ceResSet.Dispose();
}
if (dataGrid1 != null) dataGrid1.Dispose();
this.Close();
}
everything is OK. So i tried put datagrid1.Dispose() on override OnClosing
and override OnClosed but with no change - DisposedException still occurs.
So, what I'm doing wrong?
I am still learning C#, so please bear with me.
I have a two Form, from first I open second form with datagrid. When I
Dispose datagrid second time I get a ObjectDisposedException.
In first (main) form I have a button with code under onclick event:
temp_n = this.Text;
this.Text = string.Empty;
Form1 frm1 = new Form1;
frm1.ShowDialog();
frm1.Dispose();
this.Text = temp_n;
and in second form:
private void Form1_Load(object sender, EventArgs e)
{
ceCmd = Global.DatabaseConnection.CreateCommand();
ceCmd.CommandText = "select col1,col2 from table";
ceCmd.CommandType = CommandType.Text;
ceResSet = ceCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
dataGrid1.DataSource = ceResSet;
}
and
private void Form1_Closed(object sender, EventArgs e)
{
if (ceResSet != null)
{
ceResSet.Close();
ceResSet.Dispose();
}
if (dataGrid1 != null) dataGrid1.Dispose();
}
and when I twice opened and closed second Form i get a
ObjectDisposedException on
"if (dataGrid1 != null) dataGrid1.Dispose();"
it's strange to me because when i put button on second form and add event:
private void Button_Click(object sender, EventArgs e)
{
if (ceResSet != null)
{
ceResSet.Close();
ceResSet.Dispose();
}
if (dataGrid1 != null) dataGrid1.Dispose();
this.Close();
}
everything is OK. So i tried put datagrid1.Dispose() on override OnClosing
and override OnClosed but with no change - DisposedException still occurs.
So, what I'm doing wrong?