|
I want to dispose my previous form on the after select event of tree view control but when i try to do so i get the following exception message
System.ObjectDisposedException: Cannot access a disposed object named "TreeView".
Object name: "TreeView".
I m building Windows application In C# 2003.Thanx for Ur help
|
|
|
|
|
Sounds like you're disposing too soon. Can we see some code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
private void TreeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
switch(name)
{
case "1":
{
Form3 f=new Form3();
f.Show();
this.close();
break;
}
}
}
My code is like this. I am opening new form and disposing the current form.
|
|
|
|
|
Hello,
If 'this' is the main form, you are not able to Close (Dispose) without ending the Application.
All the best,
Martin
|
|
|
|
|
"this" is not my main form. i know i cant close my main form. This is just another form which i want to close.
|
|
|
|
|
Hello,
Is the some other code executed after the switch case statement?
Try to debug!
All the best,
Martin
|
|
|
|
|
OK, this can't work. You're opening an instance of Form3 ( please tell me it's not called that ). But, that instance exists as a child of the current form. So, when you close the current form, the Form3 instance, as a child, will also be disposed of.
The Show() method should only be used to show a form that is a member variable, otherwise you lose all references to it.
Your best bet here is to make Form3 and this form user controls and show them both on teh one form, just hide the one you don't want.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello Christian!
I also had this in mind, but made a little test application, which works well for me.
Christian Graus wrote: So, when you close the current form, the Form3 instance, as a child, will also be disposed
I don't think it's a child Form per default!
I assume there is some other code executed on Form2 after the Close call.
All the best,
Martin
|
|
|
|
|
Hello,
I am working on a quick file browser project. i need to find a way to split a path:
(c:/somedir/somefile.txt)
into a string array:
[0] c
[1] somedir
[2] somefile.txt
is there any built in functionality to do this in c#? if not, does anybody know of any way that i can do this? Thank you very much for any help that you might be able to give, it will be much appreciated.
thanks, Andrew.
|
|
|
|
|
u can try
string path ="c:/somedir/somefile.txt";
string[] var = path.Split('/');
this will give array of strings in variable var
var[0]=c:
var[1]=somedir
var[2]=somefile.txt
rahul
|
|
|
|
|
Much easier
add
using System.IO;
to the top of your file
Then you can use
<br />
string strFile = @"c:\file\file.txt";<br />
string strTemp = Path.GetFileName(strFile);
strTemp = Path.GetDirectoryName(strFile);
strTemp = Path.GetPathRoot(strFile);
Problem with the earlier suggestion is that it won't help with more than a single directory - you can't gaurantee that item 3 in the array will be the filename every time, because one more layer such as
c:\somedir\somsubdir\somefile.txt
will force the filename into the 4th spot - at least using Path functions you can always get the Drive, Actual Directory and Actual file....
After that you can put them into an array
Mark.
-- modified at 0:03 Wednesday 18th April, 2007
|
|
|
|
|
Mark Greenwood wrote: you can't gaurantee that item 3 in the array will be the filename every
No, but you can use the array length to work that out, and you can move one step at a time, too. I'd use the System.IO methods, having said that. They are just more self documenting.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi, u can use the split method of the string and pass the "/" as the parameter, this will return u an array as u wish to have...
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Everybody can show me the way can add a Form to TabControl in other form in C#.NET 2005? I'm a beginner. Thank you very much!
|
|
|
|
|
Maybe you meant that you want to add a tab panel?
Just find propety 'TabPages' in properties list. Click the button '...' beside, and then add more taps in dialog tabpage collections editor.
Have funs.
LC
|
|
|
|
|
Thanks your answer. But I designed a window form and now I creat a new window form has a TabControl. And I want to add fist form to this TabControl. How do I make its? Thanks!
-- modified at 23:24 Tuesday 17th April, 2007
|
|
|
|
|
Hello,
This is just not possible.
You can add a TpPage to the TabPages property of the TabControl (As someone said before).
Instead of your self designed Form you should design a UserControl and add this on one of the TabPages.
All the best,
Martin
|
|
|
|
|
It is possible but you must use non-microsoft controls (for example Infragistics has control for that). You must override ms tabcontrol and implement it. I have my overriden tabconrol if you want source just give me your email to send it. I'm now at work but when go back at home i will send it code.
Greetings,
Svetlin Ralchev
.NET Software Developer
InterConsult Bulgaria Ltd.
www.icb.bg
Return to innocence
|
|
|
|
|
Thanks but no need for that.
My answer was based on the fact that he whants to use standard MS controls.
All the best,
Martin
|
|
|
|
|
Hi,
I'm writing a program to monitor processes in computer. I used class Process in namespace System.Diagnostics. But it seems there no information about the parent process of a process such as id or process_name in this class. So, if i want to know information about the parent process of a process (or child processes of a process), how must i do?
LC
|
|
|
|
|
You can't find it because this relationship doesn't exist. Process cannot have child processes, at least not at the O/S level. A process can launch another process and treat it as a child, but the O/S doesn't recognize the significance.
You can, however, have multiple processes running under the same job object though, so the processes can be managed as a unit. But, that in no way means that every process is running under a job object. A process can be created without a job!
There is no support in the .NET Framework BCL for jobs though, so you'd have to go directly to the Win32 API to enumerate the processes under each job.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks for your answer. I'll use another way (API, as you suggested, maybe)
|
|
|
|
|
Hi, I'm wondering if it's possible at all to detect whether the user has clicked the up or the down button specifically.
Thanks
|
|
|
|
|
I think you can't................
My small attempt...
|
|
|
|
|
Get the keycode of the Key and
Compare it with the UP and Down button Keycode
karthick
|
|
|
|