ListView不会显示添加的值 [英] ListView will not display added values

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

问题描述

我今天在ListView上度过了最艰难的时光。代码看起来不错,但是当我运行它时,我看不到ListView中的数据(它只是完全空白)。请帮助,我已经尝试过所有但仍然无法开始工作





I am having the hardest time with ListView today. The code looks good but when i run it i do not see data in the ListView (it''s just totally blank). Please help, I have tried everything but still can''t get it to working


Dim T As New Form1

Dim arr(3) As String

arr(0) = "a"
arr(1) = "b"
arr(2) = "c"
arr(3) = "d"

Dim itm As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(arr)

T.ListViewRev.Items.Add(itm)

T.ShowDialog()

推荐答案





i建议你在Form1的Load事件上绑定列表视图。



Hi,

i suggest you to bind the list view on Load event of Form1.

'Open the Form1
Dim T As New Form1
T.ShowDialog()




'Form1 Load event
Protected Sub Form1_Load(sender As Object, e As EventArgs)

'Bind the list view
Dim arr(3) As String
 
arr(0) = "a"
arr(1) = "b"
arr(2) = "c"
arr(3) = "d"
 
Dim itm As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(arr)
 
ListViewRev.Items.Add(itm)
End Sub





希望它有效。



hope it works.


这不是它的工作原理。 ListViewItem 的构造函数创建一个带有子项的项目:

http://msdn.microsoft.com/en-us/library/faw83h4f.aspx [ ^ ]。



子项用于使用值 System.Windows.Forms.View.Details 查看,其中显示,所以你需要设置查看属性,定义列等。请参阅:

http://msdn.microsoft.com/en-us/library/system.windows.forms .listview.view.aspx [ ^ ],

http://msdn.microsoft.com /en-us/library/system.windows.forms.view.aspx [ ^ ]。



上面引用的最后一个MSDN页面显示了一个<$的代码示例c $ c>详细信息,和子项。如果这是您想要的,请检查它并添加代码中缺少的内容。如果您需要不同类型的视图,请阅读更多文档。



-SA
This is not how it works. This constructor of ListViewItem creates an item with sub-items:
http://msdn.microsoft.com/en-us/library/faw83h4f.aspx[^].

Sub-items are used in the View with the value System.Windows.Forms.View.Details, which show Columns, so you need to set the View property, define columns, etc. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.view.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx[^].

The last MSDN page referenced above shows a code sample with Details, Columns and sub-items. If this is what you wanted, check it and add what is missing from your code. If you need different kind of view, read the documentation more.

—SA


I认为问题是我需要添加一列
I think the problem was that i needed to add a column


这篇关于ListView不会显示添加的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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