listview和listbox不显示项目 [英] listview and listbox don't display items

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

问题描述

我有一个带有几种表单的c#windowsform应用程序,在其中一种表单中,我有2列listview.当我将文本添加到列表视图的项目时,什么也没有显示.我知道这些项正在添加,因为出现了垂直滚动条,并且我检查了这些项在调试器中是否具有适当的文本.有谁知道为什么不显示文本以及如何使它们显示?显然其他人在列表视图中遇到了这个问题,但是我没有看到任何发布的解决方案.同样的事情也以另一种形式出现在列表框中-字符串已正确添加到列表框中的项目,但未显示.提前谢谢.

男孩,我觉得很蠢!我假设文本颜色默认为黑色,但它是白色,与背景色相同.感谢您的帮助!

糟糕,也许我太草率了.那是列表框的问题,而不是列表视图的问题.列表视图的文本颜色(前颜色)设置为黑色,背景颜色设置为白色.这是列表视图的代码:

加载中:

I have an c# windowsform app with several forms and in one of the forms I have a 2 column listview. When I add the text to the items of the listview, nothing is shown. I know the items are getting added because the vertical scroll bar appears, and I checked that the items had the appropriate text in the debugger. Does anyone know why the text is not shown and how I can get them to appear? Apparently others have had this problem with listviews but I didn''t see any solutions posted. The same thing happens in the listbox in another form - strings are getting added to the items of the listbox correctly but they are not shown. Thanks in advance.

Boy, do I feel stupid! I assumed the text color was defaulted to black but it was white, same as the backgound color. Thanks for your help!

Oops, maybe I was too hasty. That was the problem with the listbox but not the listview. The text color (fore color) for the listview was set to black and background color to white. Here is the code for the listview:

In load:

columnHeader2.Text = "col 1";
columnHeader1.TextAlign = HorizontalAlignment.Center;
columnHeader1.Width = this.Width / 2 - 6;

columnHeader2.Text = "col 2";
columnHeader2.TextAlign = HorizontalAlignment.Center;
columnHeader2.Width = this.Width / 2 - 6;

lvwCOMMIO.Columns.Add(columnHeader1);
lvwCOMMIO.Columns.Add(columnHeader2);


当我尝试更新列表视图时:(message1和message2是字符串)


When I try to update the listview: (message1 and message2 are strings)

ListViewItem item1 = new ListViewItem(message1, 0);
item1.SubItems.Add(message2);

lvwCOMMIO.Items.Add(item1);


我正在测试InvokeRequired并在列表视图上将Invoke()与委托一起使用,但这是错误的,因此我删除了该测试.

是的,我已将视图类型设置为详细信息".


I was testing for InvokeRequired and using Invoke() with a delegate on the listview but it''s false so I deleted that test.

Yes, I have the view type set to Details.

推荐答案

在Windows窗体中.单击列表视图框.您会看到一个小的三角形的东西.单击它,然后将下拉列表框之一更改为Details.它应该显示您想要的内容.
In windows forms. click on the listview box. You will see a small triangle thing. Click it, and change one of the drop down boxes to Details. It should show you what you want.


这篇关于listview和listbox不显示项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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