txtEditor.Text =没有选择项目; } 其他 { txtEditor.Text = File.ReadAllText(openFileDialog.FileName); } } I NEED IT WHEN THE LISTBOX SELECTED ITEM TO DISPLAY IT ON TEXTBOX AND ITS MULTISELECT TXT MY CODE BELOW THE RESULT WAS IT REAPETS THE FILE PLEASE HELP!!!What I have tried:OpenFileDialog openFileDialog = new OpenFileDialog(); private void btnOpenFiles_Click(object sender, RoutedEventArgs e) { openFileDialog.Multiselect = true; openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (openFileDialog.ShowDialog() == true) { foreach (string filename in openFileDialog.FileNames) { lbFiles.Items.Add(System.IO.Path.GetFileName(filename)); } } } private void lbFiles_SelectionChanged(object sender, SelectionChangedEventArgs e) { object item = lbFiles.SelectedItem; if (item == null) { txtEditor.Text = "No Item Selected"; } else { txtEditor.Text = File.ReadAllText(openFileDialog.FileName); } }推荐答案 txtEditor.Text = File.ReadAllText(openFileDialog.FileName); 您正在打开 openFileDialog 中的文件,而不是 ListBox 。 [edit] 代码应该是这样的: You are opening the file from the openFileDialog instead of the one in the selected item of the ListBox.[edit]The code should be something like:private void lbFiles_SelectionChanged(object sender, SelectionChangedEventArgs e){ object item = lbFiles.SelectedItem; if (item == null) { txtEditor.Text = "No Item Selected"; } else { txtEditor.Text = File.ReadAllText(item.ToString()); }} [/ edit] [/edit] 这篇关于我如何... wpf openfiledialoge multiselect从列表框传递到所选项目的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-26 18:37