C# 跳过复选框listView
我有一个 listView,其中列出了一堆文件,以及一组允许用户从 FTP 服务器下载它们的复选框,如下所示:
Filename Size Last modified New version
[ ] someimage.jpg 120 kB 2010-01-13 16:12:59 Yes
[ ] otherfile.zip 12 kB 2009-12-29 09:33:15 No
[ ] folder - - -
虽然我不想在文件夹上有一个复选框,但我确实需要它(文件夹)将显示在列表中。
我该如何最好地解决这个问题?
更新:我正在使用 Windows 窗体。
I have a listView that lists a bunch of files, and a set of checkboxes that allow users to download them from an FTP server, like so:
Filename Size Last modified New version
[ ] someimage.jpg 120 kB 2010-01-13 16:12:59 Yes
[ ] otherfile.zip 12 kB 2009-12-29 09:33:15 No
[ ] folder - - -
I don't want to have a checkbox on the folder though, but I do need it (the folder) to be displayed in the list.
How do I best sort this?
Update: I'm using Windows Forms.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将列表框置于 OwnerDraw 状态(将 OwnerDraw 属性设置为 true)。然后定义 DrawSubItem 和 DrawColumnHeader 事件处理程序。在 DrawSubItem 中,为需要绘制复选框的项目执行默认绘制。检查下面的代码;它应该跳过为文本字段中带有“1”的项目绘制复选框,并仅绘制项目的文本。
作为替代方案,您可以使用 进行自己的复选框绘制CheckBoxRenderer 类
希望这有帮助,问候
you can put your listbox into the OwnerDraw state (set true to the OwnerDraw property). Then define DrawSubItem and DrawColumnHeader event handlers. In the DrawSubItem do default painting for items which do require checkboxes to be drawn. Check the code below; it should skip drawing a checkbox for the item with "1" in its text field and paint only item's text.
as an alternative you can do your own checkbox painting by using CheckBoxRenderer class
hope this helps, regards