listview的新实例混淆请解释 [英] new instance of listview confused please explain
问题描述
大家好,我是一个相当新的 VB.NET 学生.我第一次使用 listview 对象.我找到了一些代码来完成这项工作.基本上我想将信息添加到第二列和第一列.这段代码工作正常,但我很难理解它为什么工作.谁能给我解释一下?
Hello everyone I am a fairly new VB.NET student. I am working with a listview object for the first time. I found bits and pieces of code to make this work. Basically I want to add info to the second column and the first column. This code works fine but I am having a hard time trying to understand why it works. Can someone explain it to me please?
我不明白为什么需要将它调暗为新的列表视图.为什么我不能只做 listview.subitems.add ......我知道没有这个命令但是为什么?为什么我需要创建一个新的 listview 实例来填充第二列.
I don't understand why the dim itm as new listview is needed. Why can I not just do listview.subitems.add... I know there is no command for this but why? Why do I need to create a new instance of listview to fill the second column.
Private Sub btnAddItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddItem.Click
Dim itm As New ListViewItem 'Add items to listbox
itm = lstData.Items.Add(txtInput.Text) 'Add data from txtbox
itm.SubItems.Add(txtInput.Text) ' Add data from txtbox
End Sub
推荐答案
我不明白为什么需要将它调暗为新的列表视图
它不是,您正在创建一个新的 ListViewItem
添加到 LV.
I don't understand why the dim itm as new listview is needed
its not, you are creating a new ListViewItem
to add to the LV.
ListView 包含对象 - ListViewItems、Groups 和 Columns,最后 2 个控制事物的显示方式.它是包含 SubItems
的 ListViewItem
(LV.Items 是 ListViewItems
的集合,而 SubItems 是 ListViewItem.ListViewSubItem 的集合
.)
the ListView contains objects - ListViewItems, Groups and Columns with the last 2 controlling how things are displayed. It is the ListViewItem
which contains SubItems
(LV.Items is a collection of ListViewItems
, while SubItems is a collection of ListViewItem.ListViewSubItem
.)
为什么我不能只做 listview.subitems.add
因为 LV 不知道将新的 SubItem 与哪个 Item 关联(即在哪一行显示它).
Why can I not just do listview.subitems.add
Because the LV would have no idea which Item to associate the new SubItem with (ie which row to display it on).
itm.SubItems.Add(txtInput.Text)
这会动态创建一个新的 SubItem.如果您想设置的不仅仅是文本,您可以实例化一个 ListViewItemSubItem
来设置其他属性(ForeColor、Name、Font、Tag...)
This creates a new SubItem on the fly. If you want to set more than just the text, you can instance a ListViewItemSubItem
to set other properties (ForeColor, Name, Font, Tag...)
要知道的重要一点是它不是网格 - 您可以轻松编辑标签/项目文本,但不能轻松编辑子项目文本(内联).而不是网格,查看资源管理器中使用的示例 - 您可以编辑文件名(==项目),但不能编辑大小、日期等等(==子项目)
An important thing to know is that it is not a Grid - you can easily edit the Label/Item text, but not the Subitem text (inline). Rather than a Grid, look at Explorer for an example in use - you can edit the FileName (==Item), but not the size, date, etc etc etc. (== SubItems)
这篇关于listview的新实例混淆请解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!