Solved

How to display Select Computer stantard dialog

Posted on 2004-09-14
8
738 Views
Last Modified: 2012-08-14
I'd like to display standard Select Computer dialog, like the one in Computer Management Console -> Right click -> Select "Connect to Another Computer" -> Browse
How can it be done from C#?
Any other standard network browse dialog also will be OK.

Any help will be appreciated,
Jigit
0
Comment
Question by:Jigit
8 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 500 total points
Comment Utility
There is no such dialog but you can make your own... eg i am filling all the computers in a listbox:

DirectoryEntry root  = new DirectoryEntry("WinNT:");        
               
foreach (DirectoryEntry dDom in root.Children)                  
      foreach (DirectoryEntry dPC in dDom.Children)                  
            if (dPC.SchemaClassName == "Computer" )
                  listBox1.Items.Add (dDom.Name + "/" + dPC.Name);            

0
 
LVL 5

Expert Comment

by:tomasX2
Comment Utility
     FolderBrowserDialog di = new FolderBrowserDialog();
      di.ShowDialog();
0
 
LVL 4

Author Comment

by:Jigit
Comment Utility
tomasX2, thank you. Your suggestion allows to browse for folders, while I need only computers.

Desp, your suggestion is closer to what I need. The only problem I encounter with it is performance. The whole enterprise network is being scanned for all the object.

Is there possibility to limit it only to computers?
Or display only domain controllers and expand their networks on mouse click? (Maybe filling them in a tree view)
Does it support WinNT Networks and Active Directory? What has "LDAP" to do with it?

Thanks,
Jigit
0
 
LVL 19

Expert Comment

by:Desp
Comment Utility
you can put a line
Application.Doevents();
to improve the performance (compare the performance by commenting the line and run the code again)

for active directory , LDAP thingy check this:
http://www.c-sharpcorner.com/Code/2002/Aug/ListAllComps.asp
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 4

Author Comment

by:Jigit
Comment Utility
I'm trying to build my own ComputerBrowserDialog using your suggestions. I'm filling Domain Controllers into TreeView on form load. I'd like to expand a network when user double clicks on it. How can I do it? My code is published below, but it does not react on clicking on a node. Any ideas?

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.DirectoryServices;

namespace MMCTest
{
      /// <summary>
      /// Summary description for BrowseServerForm.
      /// </summary>
      public class BrowseServerForm : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Button okButton;
            private System.Windows.Forms.Button cancelButton;
            private System.Windows.Forms.ListBox listBox1;
            public string ServerName = null;
            private System.Windows.Forms.TreeView computersTreeView;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public BrowseServerForm()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.okButton = new System.Windows.Forms.Button();
                  this.cancelButton = new System.Windows.Forms.Button();
                  this.listBox1 = new System.Windows.Forms.ListBox();
                  this.computersTreeView = new System.Windows.Forms.TreeView();
                  this.SuspendLayout();
                  //
                  // okButton
                  //
                  this.okButton.Location = new System.Drawing.Point(392, 352);
                  this.okButton.Name = "okButton";
                  this.okButton.TabIndex = 1;
                  this.okButton.Text = "OK";
                  this.okButton.Click += new System.EventHandler(this.okButton_Click);
                  //
                  // cancelButton
                  //
                  this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                  this.cancelButton.Location = new System.Drawing.Point(160, 360);
                  this.cancelButton.Name = "cancelButton";
                  this.cancelButton.TabIndex = 2;
                  this.cancelButton.Text = "Cancel";
                  this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
                  //
                  // listBox1
                  //
                  this.listBox1.Location = new System.Drawing.Point(32, 40);
                  this.listBox1.Name = "listBox1";
                  this.listBox1.Size = new System.Drawing.Size(344, 225);
                  this.listBox1.TabIndex = 3;
                  //
                  // computersTreeView
                  //
                  this.computersTreeView.ImageIndex = -1;
                  this.computersTreeView.Location = new System.Drawing.Point(392, 48);
                  this.computersTreeView.Name = "computersTreeView";
                  this.computersTreeView.SelectedImageIndex = -1;
                  this.computersTreeView.Size = new System.Drawing.Size(360, 272);
                  this.computersTreeView.TabIndex = 4;
                  //
                  // BrowseServerForm
                  //
                  this.AcceptButton = this.okButton;
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.CancelButton = this.cancelButton;
                  this.ClientSize = new System.Drawing.Size(786, 418);
                  this.Controls.Add(this.computersTreeView);
                  this.Controls.Add(this.listBox1);
                  this.Controls.Add(this.cancelButton);
                  this.Controls.Add(this.okButton);
                  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
                  this.Name = "BrowseServerForm";
                  this.Text = "Browse Server";
                  this.Load += new System.EventHandler(this.BrowseServerForm_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            private void BrowseServerForm_Load(object sender, System.EventArgs e)
            {

                  computersTreeView.BeforeExpand += new TreeViewCancelEventHandler(computersTreeView_BeforeExpand);
                  
                  DirectoryEntry root  = new DirectoryEntry("WinNT:");    
                  foreach (DirectoryEntry dDom in root.Children)
                  {
                        TreeNode node = new TreeNode();
                        node.Text = dDom.Name;
                        computersTreeView.Nodes.Add ( node );    
                  }
            }

            private void okButton_Click(object sender, System.EventArgs e)
            {
                  this.DialogResult = DialogResult.OK;
                  if ( listBox1.SelectedItem != null )
                  {
                        ServerName = listBox1.SelectedItem.ToString();
                  }
            }

            private void cancelButton_Click(object sender, System.EventArgs e)
            {
                  this.DialogResult = DialogResult.Cancel;
            }

            private void computersTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
            {
                  TreeNode node = sender as TreeNode;
                  if ( node == null ) return;

                  DirectoryEntry root  = new DirectoryEntry("WinNT:");        
                  foreach (DirectoryEntry dDom in root.Children)
                  {
                        if ( dDom.Name != node.Text ) continue;

                        foreach (DirectoryEntry dPC in dDom.Children)              
                              if (dPC.SchemaClassName == "Computer" )
                                    node.Nodes.Add ( dPC.Name);      
                  }
            }
      }
}
0
 
LVL 10

Expert Comment

by:eternal_21
Comment Utility
Change:

  computersTreeView.DoubleClick += new TreeViewCancelEventHandler(computersTreeView_BeforeExpand);

to:

  computersTreeView.DoubleClick += new EventHandler(computersTreeView_DoubleClick);


Change:

  private void computersTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)

to:

  private void computersTreeView_DoubleClick(object sender, EventArgs e)


And finally, change:

  TreeNode node = sender as TreeNode;

to:

  TreeNode node = ((TreeView)sender).SelectedNode;


You may also find this of interest: http://www.codeproject.com/csharp/csenumnetworkresources.asp
0
 
LVL 4

Author Comment

by:Jigit
Comment Utility
eternal_21, thanks for your comment. Let me argue with you: node expansion may be done not only by double-clicking, but also by presssing "+" on the keyboard or maybe some other event. I've already implemented it using BeforeExpand. So all the points go to Desp, who was the first to suggest this solution.

Thanks to all of you , guys!!!
0
 
LVL 19

Expert Comment

by:Desp
Comment Utility
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now