|
Since the TreeNode doesn't fire any everys, you can't wire up any code to it. The DoubleClick event is fired by the TreeView control, not the TreeNode you clicked on. In your DoubleClick event handler, you'll used the SelectedNode property to find out which node the used clicked on. You can modify the function that the designer creates by renaming the treeView1_AfterSelect function to treeView1_DoubleClick and making the same change in the Windows Forms Designer gnerated code section. A search and replace for "AfterSelect" ought to do it nicely.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I tried replacing "AfterSelect" with DoubleClick, but when I compile I get this error:"D:\Documents\Visual Studio Projects\WindowsApplication5\Form1.cs(70): Cannot implicitly convert type 'System.Windows.Forms.TreeViewEventHandler' to 'System.EventHandler'
" from this line: "this.treeView1.DoubleClick += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_DoubleClick);". I tried casting this.treeView1.DoubleCLick to a TreeViewEventHandler, but it won't let me do that either. Any suggestions? (sorry, I'm very new to C#) Also, would it be possible to change the event from DoubleClick to when the user presses the "Enter" key? If so, what is the event for this?
Thanks,
Justin
|
|
|
|
|
Oooops... My mistake. That line should read:
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
There is no specific event fired for the Enter key. You might want to look into handling the KeyPress event, or KeyDown/KeyUp events, or possibly the Click event, to see which one will suit your needs. You can do this easily enough by displaying a MessageBox when those event fire.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This line:
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
Still throws an error, because I'm not passing this.treeView1_DoubleClick any parameters. I'm not sure what I should pass here, other than (?nulls), because I don't have a sender object or an event arg to pass it.
Here is the error:
Method 'WindowsApplication5.Form1.treeView1_DoubleClick(object, System.Windows.Forms.TreeViewEventArgs)' does not match delegate 'void System.EventHandler(object, System.EventArgs)'
Sorry if this seems elementary, I'm still learning..
Thank you for your patience and your helpful responses,
Justin
|
|
|
|
|
Because DoubleClick is not of type TreeViewEventHandler , it is of type EventHandler , as the documentation would tell you if you read it.
You can get the TreeNode that was double-clicked like so:
this.treeView1.DoubleClick += new EventHandler(treeView1_DoubleClick);
private void treeView1_DoubleClick(object sender, EventArgs e)
{
Point p = PointToClient(MousePosition);
TreeNode node = GetNodeAt(p);
if (node != null)
{
}
} If you want to use the Enter key instead (really, it's better to use both), then handle the KeyDown event and get the select node using the TreeView.SelectedNode property.
If you want to know what events, methods, and properties are available for the TreeView , then you really should read the class documentation. See TreeView Members[^] in the .NET Framework SDK. The only true way to learn what all is available is to read.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have looked at the SDK, but it is all still a little overwhelming to a new .Net programmer. I guess I just need more practice with the syntax and necessary declarations of form control objects.
Also, its still throwing an error, because I'm not passing treeView1_DoubleClick any parameters in this line: this.treeView1.DoubleClick += new EventHandler(treeView1_DoubleClick);
I'm not sure what sender object or event args I should pass here, since I'm really just initializing the DoubleClick event...
Error:'WindowsApplication5.Form1.treeView1_DoubleClick(object, System.Windows.Forms.TreeViewEventArgs)' does not match delegate 'void System.EventHandler(object, System.EventArgs)'
Thanks for your help and patience,
Justin
|
|
|
|
|
j1e1g1 wrote:
I have looked at the SDK, but it is all still a little overwhelming to a new .Net programmer. I guess I just need more practice with the syntax and necessary declarations of form control objects.
It's not about syntax; it's about the classes available to a language (a "syntax"). The base class library (BCL) and any other class libraries for .NET are available to all managed languages like C#, VB.NET, etc. They call compile to Intermediate Language (IL), which is one of the features of the Common Language Infrastructure (CLI). The only way to learn all this is to read.
You don't pass parameters to a delegate (your EventHandler ) - the caller does. But the signature for the method has to match declaration of the delegate. Look at my code sample again; your treeView1_DoubleClick has to be declared as this:
private void treeView1_DoubleClick(object sender, EventArgs e)
{
} The important aspects of this method signature are in bold.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
The solution depends on the treeview depth. If it finite and small (e.g. 3 fixed levels), you can write a function that will tell your program, what kind of node it clicked on based on its treeview position.
If the depth is indeterminate, you can assign some kind of identity object to the TreeNode's Tag property to tell one node type from another.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
I write the following code in my porject:
<br />
ppApp = new PowerPoint.Application();<br />
<br />
objPres = ppApp.Presentations.Add(MsoTriState.msoCTrue);<br />
<br />
for(int i=0; i<Page_number; i++)<br />
{<br />
objSlide = objPres.Slides.Add(i+1, PowerPoint.PpSlideLayout.ppLayoutText);<br />
<br />
objShape = objSlide.Shapes.AddPicture(SavePath + "\\PSPage" + (i+1).ToString()+ ".bmp",MsoTriState.msoFalse,MsoTriState.msoTrue,9,22,702,496);<br />
<br />
<br />
objPres.SlideShowSettings.ShowType = PowerPoint.PpSlideShowType.ppShowTypeWindow;<br />
objPres.SlideShowSettings.Run();<br />
objPres.SlideShowWindow.Activate(); <br />
I can add a presentation, add a slide, insert a picture,
and I can show the SlideShowWindow,
but I don't know how to active the window in PowerPoint 2003,
to do the code ppApp.ActiveWindow.View.Paste();
and I want to show the presentation with standard mode not SlideShowWindow,
Does anyone know how to do this...??
I can't find the solutions for a long time...
|
|
|
|
|
You could try to enumerate the Windows where the Presentation is current being displayed and call Activate (untested, but it should work):
DocumentWindows windows = presentation.Windows;
if (windows.Count > 0) windows[0].Activate(); You can also enumerate the DocumentWindows (using foreach , for example) and find a named view you want, then call Activate .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
For a while now ... i keep seeing ...
[Serializable] or [other stuff] in '[]' ... and I don't fully understand what that meens .. if you can help me ... !
I'd also like to know all the thincs that can be wrote in [ ]
Lazar Mihai
Elev clasa XI C
Grup Scolar Sanitar
|
|
|
|
|
Attributes define metadata for class members.
Every Attribute is a class, e.g. SerializableAttribute. You can find more about those attribute classes in the .NET documentation.
|
|
|
|
|
|
Hello.
I've got the following problem:
There is a web application (ASP.NET), that needs to
authenticate users against local machine and Active Directory.
By default, the application works as ASPNET account (Win2000, XP).
When working on ASPNET account the apllication is able to do the following:
string path = "WinNT://" + evironment.MachineName + ",computer";<br />
DirectoryEntry entry = new DirectoryEntry(path, username, pwd);<br />
try<br />
{ <br />
Object o = entry.NativeGuid;<br />
}<br />
catch(...)<br />
{<br />
}
When run as ASPNET account (on XP) , the code is able to work correctly. However, when run as SYSTEM account, exception is thrown
"A specified logon session does not exist. It may already have been terminated."
I need to switch to system account, because I also need to authenticate users in Acitive Directory, and ASPNET this time cannnot connect to AD, whereas SYSTEM account can.
So, currently I can authenticate users either in local system (when run as ASPNET) or in AD (when run as SYSTEM), but not concurrently (i.e. I can not do this without restarting the process)
SYSTEM ASPNET (running XP)
LOCAL USERS - +
DOMAIN USES + -
SYSTEM ASPNET (running Win2000)
LOCAL USERS - -
DOMAIN USES + -
Questions:
1. Is there any way to grant local ASPNET account ability to connect to AD ?
2. Is there any way to allow SYSTEM account to authenticate users against local machine. (The inability seems ridiculous...) (Note: I cannot temporarily use impersonation [SYSTEM is granted right to
impersonate someone elese] to check credentials, since the application is a muliti user system and the fraction of time the app would work as somebody else (not system but e.g John.Smith ) would leed to errors. Ok, I might lock entire application functionality when somebody performs logon but this would be hugely ineffective and would require to redesign plenty of code. (The application is pretty complex))
Thanks for help
Michał Januszczyk
|
|
|
|
|
Michal,
I think you may get a better response if you try asking in the ASP.NET[^] forum specifically. I believe there may be some articles here on CP that cover this topic as well. HTH.
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi, i wrote a small program in C# which uses threads.
But when i close the application ( this.close() ), it is not terminating the application. Application is still running in the task manager, but all windows of the applications are got closed.
I tried with closing all the threads ( t.abort() ), but it is not working.
Can any one solve the problem ?
M.V.Ravikumar
|
|
|
|
|
Declare your threads as background threads by setting the IsBackground property true, so they do not prevent the process from terminating.
www.troschuetz.de
|
|
|
|
|
Thank you for your quick response.
It solved my problem. But i didn't get the actual thing. If you have time, please enlighten me in this area, by giving some more info.
Application.exit() or the start form.close() , are both of them equal?
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
M.V.Ravikumar
|
|
|
|
|
Ravikumar_mv wrote:
Application.exit() or the start form.close() , are both of them equal?
No they are not! The Application.Exit method informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. Whereas the Form.Close only closes a form, which doesn't necessarily result in termination of your application.
Also note what the documentation for both methods states:
"CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method."
Ravikumar_mv wrote:
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
Yes they get automatically aborted. Documentation for the IsBackground property says:
"Once all foreground threads belonging to a process have terminated, the common language runtime ends the process by invoking Abort on any background threads that are still alive."
www.troschuetz.de
|
|
|
|
|
Ravikumar_mv wrote:
If we set isbackground property to true. after the form.close(), all the threads of the application will automatically aborted?
It is best to set the .IsBackground property to true BEFORE you start the thread, not when you end it.
Also, writing your threads so that they can exit gracefully. This means handling some kind of flag or exception that signals the thread to close any open resources it has before it quits. Just doing a threadObject.Abort() on it will terminate the thread at just about any point, not necessarily when it's safe to do so.
For an example of this, see this[^] link on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you for ur quick response. It solved my problem.
Sorry for my late response.
M.V.Ravikumar.
|
|
|
|
|
Hi,
I just can export table structure to excel. No data found. Pls help.
here is my code :
......
this.sqlDataAdapter.Fill(this.dsTables, "testTable");
DataGrid dg = new DataGrid();
dg.DataSource = this.dsTables.Tables["testTable"];
dg.DataBind();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.enableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
dg.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
Thanks
Wilson
|
|
|
|
|
This question really belongs in the ASP.NET forum. It really has nothing to do with C#, even though the codebehind is written in it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Have you tried debugging it? Did the dsTables DataSet contain any data? Did you remember to use the SqlDataAdapter.TableMappings to make sure that the first result set ("Table") matched up with "testTable"? The SqlDataAdapter.SelectCommand may have in fact retrieved data but unless the table mappings are set up correctly, the "testTable" DataTable won't contain any data, so nothing but a skeleton table would be output to the HtmlTextWriter .
Step through the code and check the state of the variables with each relevent step (like after you Fill the DataSet , after you call db.DataBind , etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
when i drop a DataAdapter on the form and use "generate dataset" command(by right clicking the dataadapter on the form), this error display :
there were problems generating winapplication1.DataSet1. To resolve this problem , build the project, fix any errors , and then generate the dataset again.
then i creat another application and another database but this message display again.(when i build project, has not error!)
I also reinstall my VS.NET completely, but i have problem with this error too.
thanks.
|
|
|
|
|