|
does not work at all
Greetings....
|
|
|
|
|
hi
folderdlg.SelectedPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|
|
|
|
Hi there!
I had the same strange problem. Make sure that the default threading model for your application is single-threaded apartment. When the default threading model is multithreaded apartment, the FolderBrowserDialog doesn't display the filetree for selecting a folder.
<br />
[System.STAThread]<br />
static void Main() <br />
{<br />
System.Windows.Forms.Application.Run(new MainForm());<br />
}<br />
Hope this helps? Otherwise there may be some more difficulties for displaying the FolderBrowserDialog.
|
|
|
|
|
Thank you very much, that was the solution
Greetings....
|
|
|
|
|
A couple things to add:
When you use ShowDialog to show a modal form, the form/dialog must be disposed. Also, the default for the RootFolder is already the SpecialFolder.Desktop , so you really don't need to set this.
A good way to dispose the dialog when you're done is like so:
using (FolderBrowserDialog dialog = new FolderBrowserDialog())
{
DialogResult result = dialog.ShowDialog(this);
if (result == DialogResult.OK)
somePathVariable = dialog.SelectedPath;
} This makes sure that the dialog is disposed even if an exception is thrown. If you don't, your memory consumption will continue to increase every time you show this form since the native resources aren't freed since the FolderBrowserDialog uses the SHBrowserForFolder and related native APIs.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!
I have some question regarding your comment, which is as always very instructive.
Aren't the native resources of the FolderBrowserDialog freed in the Finalize-method which will be called by the garbage collector?
Which other classes must be disposed programmatically? Every class that has unmanaged resources?
THX in advance.
|
|
|
|
|
No, native resources are not freed by the GC because they are unmanaged. Pretty much anything that implements IDisposable should be disposed of when done, like the Graphics object which many people forget when they create them (as opposed to when it's passed in a PaintEventArgs , which gets disposed by the control after calling OnPaint , for example).
There was a pretty big section in this month's MSDN Magazine which will be online early next month (more than likely) that describes well when you should dispose, when you shouldn't, and when you should implement it and where things should be freed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Good to know.
I think, i have to check my whole code for this because i always thought that the managed classes of Framework Class Library free all their resources when they are collected by GC. It's too bad i didn't learn about that earlier.
Can you provide a link where to find this article respectively where to look for it?
THX again!
|
|
|
|
|
As I mentioned, the May issue of MSDN Magazine has not been posted yet, though it was released in paper form.
You can, however, read Cleaning up Unmanaged Resources[^] in the .NET Framework SDK for more information now.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi again,
hope somebody could help me again,
<code>
string s = "<SAVE>";
textBox1.Text = textBox1.Text.Insert(0,s);
</code>
this is my Code when press a button. But in this case the String would inserted on first position in the textbox. How could i change the code to insert the code on Cursorposition. I've searched for it but found nothing that still works.
Eolus
If you want realize your dreams, you shouldn't sleep!
|
|
|
|
|
textBox1.Text.Insert(textBox1.SelectionStart, s)
« Superman »
|
|
|
|
|
Hi <<superman>>
thx for your fast reply, it works fine.
Eolus
If you want realize your dreams, you shouldn't sleep!
|
|
|
|
|
I have a .XSD file
and there are some table in this file
when a add a element in a table
a Exeception was throwed
the message is that
disobey the check or primKey or forinkey or not null
but i didn't define anything like the message sayed in that file
study everyday
|
|
|
|
|
when I use Fill Method
before Adding the element
when i use fill method there is nothing Exception
study everyday
|
|
|
|
|
This is an exception thrown by .NET - not your file. Your SQL query is returning results that violate the foreign key constraint. That is, if you have relationships set up in your DataSet (which appears to be the case) and you insert rows into the foreign table, then the foreign keys must exist in the primary table.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to control instantiation of a class/object in c#?
I am trying to replicate the functionality of VB6 which allows you to specify whether the class can be instantiated by anyone, or whether it can only be used by other classes in the same project. What this would allow is the class being instantiated, and even returned by a "factory" construct, other code could USE the class, but it couldn't be instantiated elsewhere.
I've tried using "internal" in C#, but perhaps I'm using it wrong - or this doesn't really do what I'm wanting to do.
However, c# seems to insist that if a class is out there, it can be created anywhere.
Is there a way to do this?
Thanks.
|
|
|
|
|
The following modifiers can be used with classes:
public - Access is not restricted.
protected - Access is limited to the containing class or types derived from the containing class.
internal - Access is limited to the current assembly.
protected internal - Access is limited to the current assembly or types derived from the containing class.
private - Access is limited to the containing type.
So there is nothing wrong with using "internal", just you can instanciate the class from anywhere in the assembly.
|
|
|
|
|
This is accomplished by placing the appropriate access modifiers to both the class and the constructor.
<p>
public class MyClass
{
public MyClass() { }
}</p>
<p>
public class MyClass
{
internal MyClass() { }
}</p>
<p>
public class MyClass
{
private MyClass() { }
public static MyClass CreateInstance()
{
return new MyClass();
}
}</p>
|
|
|
|
|
hi,
i'm searching a way to retrieve a DateTime in a DataTime sql column via a datareader.
i' ve got something like this :
myCmd = new OdbcCommand( "SELECT (pretime) FROM pretable WHERE rlsname = "pwet",myConnection );
OdbcDataReader odr = myCmd.ExecuteReader();
it return me, a single cell with the datetime i want into.
but i don't manage to retrieve ths value.
if someone could help me
thx a lot
|
|
|
|
|
I hope I'm understanding the question correctly.
I think what you want to do next is something like this...
datetime dtmTime = odr.GetDate(0)
You may also want to check that the field is not null before calling the GetDate method.
|
|
|
|
|
yep i've try your solution, but it return me an error like :
System.invalidoperationexception : No data exists for the row/column.
however i check this : if(odr != null) and it enter in the if but when it execute DateTime dt1 = odr.GetDateTime(0);
i get the error :/
i don't know wht to do :/
|
|
|
|
|
You don't check if the reader is null, but if the column at index 0 is DBNull :
DateTime dt;
if (!odr.IsDBNull(0))
dt = odr.GetDateTime(0); FYI, there's no need to check if the odr variable is null. If an OleDbDataReader can't be returned for some reason, an exception will be thrown.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thx =)
now i get an error here -> if (!odr.IsDBNull(0))
and its the same error like before :/
|
|
|
|
|
What error? Be specific.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My big mistakeeeeeeeeeee lol
i was not searching for the right string in the sql db ^^
so there is no problem lol
thw a lot
|
|
|
|