1. <tfoot id='rgb4i'></tfoot>

    2. <small id='rgb4i'></small><noframes id='rgb4i'>

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

    3. <legend id='rgb4i'><style id='rgb4i'><dir id='rgb4i'><q id='rgb4i'></q></dir></style></legend>

        • <bdo id='rgb4i'></bdo><ul id='rgb4i'></ul>

        添加“标签"属性到 ListBox 的项目,如 TreeView 的节点?

        Adding a quot;Tagquot; property to a ListBox#39;s items, like a TreeView#39;s Nodes?(添加“标签属性到 ListBox 的项目,如 TreeView 的节点?)

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

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

                  <tbody id='ml3xr'></tbody>
                1. <legend id='ml3xr'><style id='ml3xr'><dir id='ml3xr'><q id='ml3xr'></q></dir></style></legend>
                  本文介绍了添加“标签"属性到 ListBox 的项目,如 TreeView 的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作一个 Windows 窗体项目,该项目将在空闲时间搜索指定文件夹中的文件.到目前为止,我的 TreeView 就像在 Windows 资源管理器中一样显示文件夹.

                  I'm making a Windows Form project that will search for files in the specified folders in my spare time. So far, I've got my TreeView that displays folders just like in the Windows Explorer.

                  我还有一个 ListBox 可以存储所有搜索结果.当我双击该列表中的一个项目时,我希望可以选择打开文件.

                  I also have a ListBox that will store all the search results. When I double click an item in that list, I want to have the option of opening the file.

                  到目前为止,我看到了三种方法:

                  So far, I see three ways of doing this:

                  1. 让 ListBox 显示完整路径.
                  2. 使用全局列表或数组来跟踪完整路径,而列表框仅显示文件名.然后使用索引来匹配对应的item.
                  3. 为我的每个 ListBox 项目添加一个Tag"属性,就像 TreeView 的节点一样.

                  对我来说,第三种方法是最吸引人的,但我不知道从哪里开始.到目前为止,我一直在摆弄一个控件库,但无济于事.

                  To me, the third method is the most appealing, but I have no idea where to start. Up until now, I've been fiddling with a Control Library to no avail.

                  我希望能够让标签以与 TreeView 类似的方式工作.因此,检索标签和设置标签的代码看起来像 ListBox1.Items[i].Tag 或者可能是 ListBox1.Tag[i] 如果前者不是可能.

                  I was hoping to be able to get the Tag to work in a similar fashion as with the TreeView. So, the code to retrieve the tag and set the tag would look like ListBox1.Items[i].Tag or maybe ListBox1.Tag[i] if the former is not possible.

                  任何帮助将不胜感激.

                  推荐答案

                  您应该创建一个自定义 SearchResult 类,该类具有返回完整路径的属性.
                  该类应覆盖 ToString() 并返回要在列表框中显示的文本.

                  You should create a custom SearchResult class with a property that returns the full path.
                  The class should override ToString() and return the text you want to display in the listbox.

                  然后您可以将您的类的实例直接放入列表框中,并将列表框中的项目投射回该类以获取属性.

                  You can then put instances of your class directly into the listbox, and cast an item from the listbox back to the class to get the property.

                  这篇关于添加“标签"属性到 ListBox 的项目,如 TreeView 的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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(更新时防止列表框滚动到顶部)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                  How do I get at the listbox item#39;s quot;keyquot; in c# winforms app?(如何获取列表框项目的“键?在 c# winforms 应用程序中?)
                  <i id='hOtaa'><tr id='hOtaa'><dt id='hOtaa'><q id='hOtaa'><span id='hOtaa'><b id='hOtaa'><form id='hOtaa'><ins id='hOtaa'></ins><ul id='hOtaa'></ul><sub id='hOtaa'></sub></form><legend id='hOtaa'></legend><bdo id='hOtaa'><pre id='hOtaa'><center id='hOtaa'></center></pre></bdo></b><th id='hOtaa'></th></span></q></dt></tr></i><div id='hOtaa'><tfoot id='hOtaa'></tfoot><dl id='hOtaa'><fieldset id='hOtaa'></fieldset></dl></div>
                      • <bdo id='hOtaa'></bdo><ul id='hOtaa'></ul>

                          <tfoot id='hOtaa'></tfoot>
                              <tbody id='hOtaa'></tbody>

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

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