使用字符串作为路径打开网络上的PC目录

时间:2012-09-28 19:36:06

标签: c# networking path directory

我的Windows应用程序只是让用户(部门老板)选择他们想要导航到我们网络上的PC目录。每个计算机名称都有一个相应的ID标记。例如,如果我想打开会计师的C盘,我会在标有选择框的组合框中选择“会计的PC”。然后我根据他们的选择设置ID标签(例如让我们说“ipx-12345”)并在文本框中显示ID标签(用于可视化验证)。我想在我的Windows资源管理器中调用路径“\\ ipx-12345 \ c $ \。注意,路径将根据他们在组合框中选择的PC而改变。”我将如何使用ID标签在文本框?

  //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";

1 个答案:

答案 0 :(得分:1)

你是如何填充这个组合框的? 如果数据来自数据库(DataSet,BindingSource等),您可以使用组合框的DataSource,DisplayMember和ValueMember。如果您没有使用数据库,并且依赖于数据列表可以实现以下内容:

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";

因此,要自动选择Combobox中的项目,您可以根据组合框SelectedValue属性中的ID获取结果。

combobox1.SelectedValue