简体   繁体   English

为什么将View设置为Details的C#ListView控件保持为空?

[英]Why does a C# ListView control with View set to Details remain empty?

I'm trying to figure out how to use a ListView control with View set to Details. 我正在试图弄清楚如何使用ViewView控件并将View设置为Details。

It's no problem if View is set to LargeIcon, SmallIcon, List or Tile, but when I set View to Details the ListView control remains empty no matter what I do. 如果将View设置为LargeIcon,SmallIcon,List或Tile,则没有问题,但是当我将View设置为Details时,无论我做什么,ListView控件都保持为空。

I have tried perhaps 100 different examples, all with the same result. 我尝试了100个不同的例子,都有相同的结果。

What may be the root to this problem? 这个问题可能是什么根源? And how can it be solved? 它怎么能解决?


Update: I'm now using an HTML table, styled with CSS and displayed in a WebBrowser control. 更新:我现在使用的是一个HTML表,用CSS设置样式并显示在WebBrowser控件中。 I think it's a rather good solution; 我认为这是一个相当不错的解决方案; if it's the final solution remains to be seen. 如果这是最终的解决方案还有待观察。

To use View.Details , you also have to supply a list of column header by filling out the Columns property of your ListView . 要使用View.Details ,还必须通过填写ListViewColumns属性来提供列标题列表。 Your items will then be displayed under the first header, and the subitems will be displayed under subsequent headers. 然后,您的项目将显示在第一个标题下,子项目将显示在后续标题下。

I was struggling with this one. 我正在努力解决这个问题。 I found that in the code, I was using to add the items, I cleared down the list first, then added the items. 我发现在代码中,我用来添加项目,我首先清除了列表,然后添加了项目。 My error was that I used myList.Clear() and not MyList.Items.Clear() , which, I can only assume, was clearing everything. 我的错误是我使用myList.Clear()而不是MyList.Items.Clear() ,我只能假设它正在清除所有内容。

Select the ListView in the designer. 在设计器中选择ListView。 Click the triangle at the upper right edge, Edit Columns, Add. 单击右上角的三角形,编辑列,添加。 Repeat as necessary for as many columns you want in the view. 根据需要在视图中重复所需的列。 You can drag the column splitters in the designer to get them to the right width. 您可以拖动设计器中的列分割器以使它们达到正确的宽度。

It's difficult to answer your question without seeing any code, but I suggest closely examining the code in this example on MSDN which uses ListView Details. 如果没有看到任何代码,很难回答你的问题,但我建议仔细检查MSDN上这个使用ListView详细信息的示例中的代码。

My guess is that you're not adding SubItems to your ListViewItem objects. 我的猜测是你没有将SubItems添加到ListViewItem对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM