Supriya
Posts: 3
Nickname: sup
Registered: Jun, 2003
Assembly reference
Posted: Jun 25, 2003 3:38 PM
Advertisement
Hi, I am just picking up C# and I need a control that allows a user to select a specific directory (not a file, just the directory). I can't seem to find such a control already in place. Now, I did find a DriveListBox and a DirListBox control They're not really what I want, but i was making do with them when I noticed that they are defined in the code as: private Microsoft.VisualBasic.Compatibility.VB6.DirListBox dirListBox1; private Microso ft.VisualBasic.Compatibility.VB6.DriveListBox driveListBox1; When i run the below code, the error I am getting is "The type or namespace name 'Compatability' does not exist in the class or namespace 'Microsoft.VisualBasic'(are you missing an assembly reference?)" How do i add assembly reference? Can anyone assist me? using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace DirectoryPickerDialog1 { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.Button button1; private Microsoft.VisualBasic.Compatibility.VB6.DirListBox dirListBox1; private Microsoft.VisualBasic.Compatibility.VB6.DriveListBox driveListBox1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; /// <summary> /// </summary> private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } /// <summary> /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// </summary> private void InitializeComponent() { System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.button1 = new System.Windows.Forms.Button(); this.dirListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.DirListBox(); this.driveListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.DriveListBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // openFileDialog1 // this.openFileDialog1.Filter = "aaa|*|aaaa|*.*"; // // button1 // this.button1.Location = new System.Drawing.Point(256, 120); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(128, 24); this.button1.TabIndex = 0; this.button1.Text = "Select"; this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown); // // dirListBox1 // this.dirListBox1.IntegralHeight = false; this.dirListBox1.Location = new System.Drawing.Point(16, 56); this.dirListBox1.Name = "dirListBox1"; this.dirListBox1.Size = new System.Drawing.Size(200, 144); this.dirListBox1.TabIndex = 1; // // driveListBox1 // this.driveListBox1.Location = new System.Drawing.Point(16, 16); this.driveListBox1.Name = "driveListBox1"; this.driveListBox1.Size = new System.Drawing.Size(200, 20); this.driveListBox1.TabIndex = 2; this.driveListBox1.SelectedIndexChanged += new System.EventHandler(this.OnDirSelectChanged); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(256, 176); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(392, 19); this.textBox1.TabIndex = 3; this.textBox1.Text = ((string)(configurationAppSettings.GetValue("textBox1.Text", typeof(string)))); // // label1 // this.label1.Location = new System.Drawing.Point(256, 152); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(112, 16); this.label1.TabIndex = 4; this.label1.Text = "Selected Directory"; // // DirectoryPickerDialog // this.AutoScaleBaseSize = new System.Drawing.Size(5, 12); this.ClientSize = new System.Drawing.Size(664, 222); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.label1, this.textBox1, this.driveListBox1, this.dirListBox1, this.button1}); this.Name = "DirectoryPickerDialog"; this.Text = "DirectoryPickerDialog"; this.ResumeLayout(false); } #endregion /// <summary> /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.textBox1.Text = this.dirListBox1.Path; } private void OnDirSelectChanged(object sender, System.EventArgs e) { try { this.dirListBox1.Path = this.driveListBox1.Drive; } catch(System.Exception exc) { MessageBox.Show(exc.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } Thanks.