Hi All,
I'm developing a windows desktop solution using VC# , I deal with my database using Dataset.
My Problem that i'm trying to call a Form to display a confirmation message after every Save, Delete ...., I wanted to make my own Message box, it works well but for one time only, if i tried to call it more than one time it gives me this exception:
<Cannot access a disposed object.
Object name: 'frmMsg'.>
My Code: -
public partial class frmOrgHierarchy : Form
-
{
-
// Create object from the Message Form
-
frmMsg objMsg;
-
-
public frmOrgHierarchy()
-
{
-
InitializeComponent();
-
objMsg = new frmMsg();
-
}
-
-
private void btnSaveSector_Click(object sender, EventArgs e)
-
{
-
try
-
{
-
objMsg.Show();
-
-
this.Validate();
-
if (sectorNameTextBox.Text.Equals("") ||
-
sectorNameTextBox.Text.Equals(null))
-
{
-
objMsg.processMessages("برجاء إدخال إسم القطاع", "err");
-
}
-
else
-
{
-
this.hR_OrgSectorsTableBindingSource.EndEdit();
-
this.hR_OrgSectorsTableTableAdapter.Update(
-
this.systemDS.HR_OrgSectorsTable);
-
hR_OrgSectorsTableBindingNavigator.Enabled = true;
-
objMsg.processMessages("تم حفظ البيانات !!", "ok");
-
}
-
}
-
catch (Exception ex)
-
{
-
//The Exception is being cached here
-
objMsg.processMessages(ex.Message.ToString(), "err");
-
}
-
}
-
Actually I don't even understand why the object has been disposed while the form is still running !!
Need help.
4 10333
I can't see any problems with the bit of code you've posted but somewhere along the line frmMsg is being disposed of.
What happens in the objMsg.processM essages() method? Have you checked that it's not being accidentally disposed of in there?
Thanks fro your reply,
The problem was here :
private void btnOK_Click(obj ect sender, EventArgs e)
{
this.Close();
}
This is the "OK" button in the message form, i replaced it with this.Hide();
i discovered this after i took my break :)
Thanks
Hi,
You can solve the error using the following way :
After doing Save,Edit and Delete you should create the object of the form you want to show. i.e.
objMsg = new frmMsg();
Currently it is created in the constructor frmOrgHierarchy () . Instead of this if you create the form object after Save operation , you will not get disposed form error because new form object will be created.
Plater 7,872
Recognized Expert Expert
I believe that calling .Close() on a form object also call the destructor (by way of calling Dispose())
Instead of .Close(), you could try using .Hide() and .Show() to hide/show the form.
Just remember to change what is displayed on it.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: salih ataoz |
last post by:
i close a form and i want to open it again it show me
Cannot access a disposed object
at vb6 this is ok
at comman1_click
form1.show
|
by: Ryan Park |
last post by:
Hi,
//SITUATION
I got a panel control that hold a certain position on a form.
Every controls or UIs are on this panel.
At certain situation, I called dispose() method of this panel control
and change it with other panel which contains other business logic and
UI controls.
|
by: Paul |
last post by:
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
If e.ChangeType = WatcherChangeTypes.Created Then
|
by: D Witherspoon |
last post by:
I use the following code to open up a form.
-------------------------------------------------------
If fImage Is Nothing Then
fImage = New frmImage
End If
fImage.Show()
|
by: theinvisibleGhost |
last post by:
I'm having a problem that occurs at random in my app.
I get an exception
"Cannot Access a disposed object"
In MSCorLib when calling boolean Change (int32, int32)
Stack trace reveals
System.Threading.Timer.Change(Int32, int32)
at Systems.Timers.UpdateTimer()
at System.Timers.Timer.set_Interval(double value)
| |
by: mthgk |
last post by:
I have a C# MDI app. The child forms do alot of work, so this work is
perfomed on a different thread created using ThreadPool.QueueUserWorkItem().
Because the status of the work is important to the user, I post the results
in a richTextBox on the child form. I have created an event to do this since
it is best to update the controls using the thread that they were created
with (or so I've read).
Anyway, the first time the user selects a...
|
by: Tracey |
last post by:
Hi, there
I met a very wierd problem. My startup form say Form1 has
a datagrid say datagrid1, when I click an item in
datagrid1, I wanna show form2. In my code, I achieved
that with:
private sub Datagrid1_currentCellChanged(ByVal sender As
Object, ByVal e As EventArgs)
....
Me.close()
dim frm2 as new form2()
|
by: Tracey |
last post by:
sorry I post this problem again. I have to stop my work
to fix the problem.
I'm doing a multi form application(Not a MDI one).
My startup form say Form1 has a datagrid say datagrid1,
when I click a grid item in datagrid1, I wanna show
form2. In my code, I achieved that with:
Public class Form1
Inherits System.Windows.Forms.Form
|
by: Rajat Tandon |
last post by:
Hi,
I have a grid which is continuously updating by the data from a external
event. When I close the form on which the grid is placed, then it gives the
error message ...
"Can not access a disposed object".
I understand that it is because as soon as the form is closed it will in
turn try to dispose the grid. I have unwired the event in the dispose of
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |