ListBox问题 [英] ListBox issue

查看:72
本文介绍了ListBox问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在ListBox上使用DataSource

时我可以使用DisplayMember和ValueMember,但是在使用时可以使用相同的技术

ListBox.Items 。添加方法?在我的应用程序中,我使用OpenFileDialog让用户选择文件名到ListBox中。问题是我不希望
希望在ListBox中显示路径+文件名,只显示文件名。但是我需要完整的路径知道文件的位置,所以我不能把它砍掉。我/ b $ b可以将DataSource与DisplayMember和ValueMember一起使用,但是后来我不会

能够删除ListBox中的任何项目,而且我必须能够要做的事情

...


非常感谢任何帮助。

Shawn

I know that I can use DisplayMember and ValueMember when using a DataSource
on the ListBox, but is it possible to use the same technique when using
ListBox.Items.Add method? In my application I use a OpenFileDialog to let
the user select filenames into the ListBox. The problem is that I don''t
wish to show the path + filename in the ListBox, only the filename. But I
need the full path to know where the file is so I can''t just chop it off. I
could use DataSource with DisplayMember and ValueMember, but then I won''t be
able to remove any of the items in the ListBox, and I have to be able to do
that...

Any help is greatly appreciated.
Shawn

推荐答案

*" Shawn" <博******** @ hotmail.com> scripsit:
* "Shawn" <bo********@hotmail.com> scripsit:
我知道在ListBox上使用DataSource时我可以使用DisplayMember和ValueMember,但是在使用ListBox.Items时可以使用相同的技术。添加方法?在我的应用程序中,我使用OpenFileDialog让用户选择文件名到ListBox中。问题是我不希望在ListBox中显示路径+文件名,只显示文件名。但是我需要完整的路径知道文件的位置,所以我不能把它砍掉。我可以将DataSource与DisplayMember和ValueMember一起使用,但后来我不能删除ListBox中的任何项目,而且我必须能够做到这一点。 ..
I know that I can use DisplayMember and ValueMember when using a DataSource
on the ListBox, but is it possible to use the same technique when using
ListBox.Items.Add method? In my application I use a OpenFileDialog to let
the user select filenames into the ListBox. The problem is that I don''t
wish to show the path + filename in the ListBox, only the filename. But I
need the full path to know where the file is so I can''t just chop it off. I
could use DataSource with DisplayMember and ValueMember, but then I won''t be
able to remove any of the items in the ListBox, and I have to be able to do
that...




查看代码,忽略文字:


< http://www.mvps .org / dotnet / dotnet / code / controls / index.html#bkm10>


-

Herfried K. Wagner

MVP·VB Classic,VB.NET

< http://www.mvps.org/dotnet>



Have a look at the code, ignore the text:

<http://www.mvps.org/dotnet/dotnet/code/controls/index.html#bkm10>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


Herfried,

我忽略了文本,但问题是没有数据集和

anwer是否有数据集,你可以在MSDN上找到正常的。

有什么问题,我也很感兴趣。


只是伪代码的东西

\\\

Dim alistbox为新列表框

dim alistitem as new listitem

listitem.add(" Herfried"," Austria")

alistbox .items.add(名单项目)

///


据我所知,这在webform上很容易,但我找不到任何

窗口表格上的文档。


你知道在哪里可以找到它,或者它是在那个页面上而且我不能

了解那个语言(不是真的)。​​

:-)

Cor
Herfried,
I have ignored the text, but the question was how without a dataset and the
anwer is with a dataset, that you can find normal on MSDN.
What is the question, and I am intrested too.

Just something in pseudocode
\\\
Dim alistbox as new listbox
dim alistitem as new listitem
listitem.add("Herfried","Austria")
alistbox.items.add(listitem)
///

As far as I know this is easy on a webform, but I could not find any
documentation on a window form for that.

Do you know where to can find it, or was it on that page and could I not
understand that language (not true).
:-)
Cor


嗨Shawn,


Herfried的例子显示,你可以将任何对象粘贴到ListBox中。 ListBox将使用ToString方法进行显示,但是当您访问代码中的列表时,您将获得整个对象。


您可以拥有一个类或结构,它包含完整的文件路径,并且只有返回尾端的

a ToString方法。


问候,

Fergus
Hi Shawn,

What Herfried''s example is showing is that you can stick any object into
the ListBox. The ListBox will use the ToString method for display purposes,
but when you access the list in your code, you get the whole object.

You could have a class or structure which holds the full filepath and has
a ToString method returning just the tail end.

Regards,
Fergus


这篇关于ListBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆