• <legend id='tFD9T'><style id='tFD9T'><dir id='tFD9T'><q id='tFD9T'></q></dir></style></legend>

    <small id='tFD9T'></small><noframes id='tFD9T'>

    <tfoot id='tFD9T'></tfoot>

      <bdo id='tFD9T'></bdo><ul id='tFD9T'></ul>

  • <i id='tFD9T'><tr id='tFD9T'><dt id='tFD9T'><q id='tFD9T'><span id='tFD9T'><b id='tFD9T'><form id='tFD9T'><ins id='tFD9T'></ins><ul id='tFD9T'></ul><sub id='tFD9T'></sub></form><legend id='tFD9T'></legend><bdo id='tFD9T'><pre id='tFD9T'><center id='tFD9T'></center></pre></bdo></b><th id='tFD9T'></th></span></q></dt></tr></i><div id='tFD9T'><tfoot id='tFD9T'></tfoot><dl id='tFD9T'><fieldset id='tFD9T'></fieldset></dl></div>

        如何在列表框中显示文件名但使用 openfiledialog 保留相对路径?

        How do I show the filename in listbox but keep the relative path using openfiledialog?(如何在列表框中显示文件名但使用 openfiledialog 保留相对路径?)

          <legend id='HN79Q'><style id='HN79Q'><dir id='HN79Q'><q id='HN79Q'></q></dir></style></legend>
          <tfoot id='HN79Q'></tfoot>

        1. <i id='HN79Q'><tr id='HN79Q'><dt id='HN79Q'><q id='HN79Q'><span id='HN79Q'><b id='HN79Q'><form id='HN79Q'><ins id='HN79Q'></ins><ul id='HN79Q'></ul><sub id='HN79Q'></sub></form><legend id='HN79Q'></legend><bdo id='HN79Q'><pre id='HN79Q'><center id='HN79Q'></center></pre></bdo></b><th id='HN79Q'></th></span></q></dt></tr></i><div id='HN79Q'><tfoot id='HN79Q'></tfoot><dl id='HN79Q'><fieldset id='HN79Q'></fieldset></dl></div>

          <small id='HN79Q'></small><noframes id='HN79Q'>

              <bdo id='HN79Q'></bdo><ul id='HN79Q'></ul>

                <tbody id='HN79Q'></tbody>

                  本文介绍了如何在列表框中显示文件名但使用 openfiledialog 保留相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作一个程序,用户需要在其中加载多个文件.但是,在 ListBox 中,我只需要显示它们加载的文件的文件名,但仍然能够使用加载的文件.所以我想隐藏完整路径.这就是我现在将文件加载到 ListBox 中的方式,但它显示了整个路径:

                  I am making a program in which the user needs to load in multiple files. However, in the ListBox I need to show only file names of the files they loaded but still be able to use the files loaded. So I want to hide the full path. This is how I load a file into the ListBox now, but it shows the whole path:

                  private void browseBttn_Click(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)
                      {
                          dllList.Items.AddRange(OpenFileDialog1.FileNames);
                      }
                  }
                  

                  推荐答案

                  // Set a global variable to hold all the selected files result
                  List<String> fullFileName;
                  
                  // Browse button handler
                      private void button1_Click(object sender, EventArgs e)
                      {
                          OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
                          OpenFileDialog1.Multiselect = true;
                          OpenFileDialog1.Filter = "DLL Files|*.dll";
                          OpenFileDialog1.Title = "Seclect 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);
                  
                              // add just the names to the listbox
                              foreach (string fileName in fullFileName)
                              {
                                  dllList.Items.Add(fileName.Substring(fileName.LastIndexOf(@"")+1));
                              }
                  
                  
                          }
                      }
                  
                      // handle the selected change if you wish and get the full path from the selectedIndex.
                      private void dllList_SelectedIndexChanged(object sender, EventArgs e)
                      {
                          // check to make sure there is a selected item
                          if (dllList.SelectedIndex > -1)
                          {
                              string fullPath = fullFileName[dllList.SelectedIndex];
                  
                              // remove the item from the list
                              fullFileName.RemoveAt(dllList.SelectedIndex);
                              dllList.Items.Remove(dllList.SelectedItem);
                          }
                      }
                  

                  这篇关于如何在列表框中显示文件名但使用 openfiledialog 保留相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                    • <bdo id='nQauC'></bdo><ul id='nQauC'></ul>
                      <legend id='nQauC'><style id='nQauC'><dir id='nQauC'><q id='nQauC'></q></dir></style></legend>

                        <i id='nQauC'><tr id='nQauC'><dt id='nQauC'><q id='nQauC'><span id='nQauC'><b id='nQauC'><form id='nQauC'><ins id='nQauC'></ins><ul id='nQauC'></ul><sub id='nQauC'></sub></form><legend id='nQauC'></legend><bdo id='nQauC'><pre id='nQauC'><center id='nQauC'></center></pre></bdo></b><th id='nQauC'></th></span></q></dt></tr></i><div id='nQauC'><tfoot id='nQauC'></tfoot><dl id='nQauC'><fieldset id='nQauC'></fieldset></dl></div>

                            <small id='nQauC'></small><noframes id='nQauC'>

                          1. <tfoot id='nQauC'></tfoot>
                              <tbody id='nQauC'></tbody>