J.C.Morris
J.C.Morris

Reputation: 803

Opening directories of PCs on a network using a string as a path

My windows application simply lets the user (department boss) choose what PC's directory they want to navigate to that's on our network. Each computer name has a corresponding ID tag. For instance, if I wanted to open the accountant's C drive, I would select "Accountant's PC" in the combobox labeled selectPC. I then set the ID tag based on their choice (for instance lets say its "ipx-12345") and display the ID tag in a text box (for visual verification). I want to invoke the path " \\ipx-12345\c$\ in my windows explorer. Note, the path will change based on what PC they chose in the combobox) How would I go about doing this using the ID tag in the textbox?

  //snippet of condition that sets the textbox's value to the ID tag of the PC chosen
  // in combo box named 'selectPC'

  if (selectPC.Text == ("Account's PC"))
            pcID.Text = "IPX-12345";

Upvotes: 0

Views: 133

Answers (1)

Julio Borges
Julio Borges

Reputation: 662

How are you populating this combobox? if the data comes from a database (DataSet, BindingSource, etc ...) you can use the DataSource, DisplayMember and ValueMember of the combobox. If you are not using a database, and is relying on a list of data can implement something like this:

Dictionary<string, string> Data = new Dictionary<string,string>();
Data.Add("Acount1", @"\\ics#$1\");
Data.Add("Acount2", @"\\ics#$2\");
Data.Add("Acount3", @"\\ics#$3\");
Data.Add("Acount4", @"\\ics#$4\");

comboBox1.DataSource = new BindingSource(Data, null);
comboBox1.DisplayMember = "Key";
comboBox1.ValueMember = "Value";

So, to automatically select the item in the Combobox, you can get the result according to the ID in the combobox SelectedValue property.

combobox1.SelectedValue

Upvotes: 1

Related Questions