说我想要listBox1
包含一组名。当有人点击其中一个名字时,它会显示listBox2
和中的姓氏已被选中。C#如何从另一个列表框中选择列表框上的对象
我似乎无法让第二个列表框已经被选中。
因此,如果选择listBox1
中的第一项,则会选择listBox2
中的第一项。等等。
怎么会这样?
下面是一些代码:
private void materialFlatButton3_Click_1(object sender, EventArgs e)
{
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
OpenFileDialog1.Multiselect = true;
OpenFileDialog1.Filter = "DLL Files|*.dll";
OpenFileDialog1.Title = "Select a Dll File";
if (OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// put the selected result in the global variable
fullFileName = new List<String>(OpenFileDialog1.FileNames);
foreach (string s in OpenFileDialog1.FileNames)
{
listBox2.Items.Add(Path.GetFileName(s));
listBox4.Items.Add(s);
}
}
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string text = listBox2.GetItemText(listBox2.SelectedItem);
textBox3.Text = text;
}
在listbox4,它显示的完整路径。在listbox2中,它只显示文件的名称。
我该如何做到这一点,当有人点击列表框2中的文件时,其相应的路径将在列表框4中选择?
使用'DataGridView'有两列'Name'和'全path' – Fabio
@Fabio我希望我的用户只能看到名称,而不是完整的路径。 –