Listview:添加新行 [英] Listview: add new row

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

问题描述

我正在编写代码以在listview中显示。我使用了For / Next循环,每次循环时都应该在listview中添加一个新行。当我执行代码时,我现在得到的只是一行。我通过将输出发送到消息框来测试循环,它显示了每个循环的消息框。所以循环工作,但它没有正确地在列表视图中显示它。我想我错过了一些会使循环过程进入listview中的下一行的东西。这是我到目前为止的代码。


Dim intMultiplicand,intMultiplier,intProduct As Integer

Dim lviTable As New ListViewItem

Const strX =" X"

Const strEquals =" ="

Dim objForm1 As New Form1


intMultiplicand = 1

intMultiplier = 1

对于intMultiplicand = 1到12

intProduct = intMultiplicand * intMultiplier

lviTable.SubItems .Add(intMultiplicand)

lviTable.SubItems.Add(strX)

lviTable.SubItems.Add(intMultiplier)

lviTable.SubItems.Add (strEquals)

lviTable.SubItems.Add(intProduct)


对于intMultiplier = 1到12

intProduct = intMultiplicand * intMultiplier

lviTable.SubItems.Add(intMultiplicand)

lviTable.SubItems.Add(strX)

lviTable.SubItems.Add(intMultiplier)

lviTable.SubItems.Add(strEquals)

lviTable。 SubItems.Add(intProduct)


下一个intMultiplier

下一个intMultiplicand


lstTable.Items.Add(lviTable)


请帮忙。

I am writing code to display in a listview. I have used a For/Next loop that should add a new line in the listview each time it loops. All i get now is one line when i execute the code. I tested the loop by sending the output to a message box and it showed a message box for every loop. So the loop works, but it is not displaying it in the listview correctly. I think I am missing something that would make the loop process go to the next row in the listview. Here is the code i have so far.

Dim intMultiplicand, intMultiplier, intProduct As Integer
Dim lviTable As New ListViewItem
Const strX = "X"
Const strEquals = "="
Dim objForm1 As New Form1

intMultiplicand = 1
intMultiplier = 1
For intMultiplicand = 1 To 12
intProduct = intMultiplicand * intMultiplier
lviTable.SubItems.Add(intMultiplicand)
lviTable.SubItems.Add(strX)
lviTable.SubItems.Add(intMultiplier)
lviTable.SubItems.Add(strEquals)
lviTable.SubItems.Add(intProduct)

For intMultiplier = 1 To 12
intProduct = intMultiplicand * intMultiplier
lviTable.SubItems.Add(intMultiplicand)
lviTable.SubItems.Add(strX)
lviTable.SubItems.Add(intMultiplier)
lviTable.SubItems.Add(strEquals)
lviTable.SubItems.Add(intProduct)

Next intMultiplier
Next intMultiplicand

lstTable.Items.Add(lviTable)

Please help.

推荐答案

我对listview不太熟悉,所以不要带任何东西我太认真了。但它看起来好像你在这些循环中所做的就是在一行中添加了许多子项(我认为相当于列)。


我并没有真正遵循代码,但如果你期望多行,那么我不期望在循环中找到 Items.Add 吗? />

(我必须在这里有一个不同版本的listview控件,因为它甚至没有 .Items - 它有 .ListItems 。所以我可能会说完全垃圾。:))
I''m not that familiar with the listview, so don''t take anything I say too seriously. But it looks to me as though all you''re doing in these loops is adding lots of subitems (which I believe are equivalent to "columns") into one row.

I didn''t really follow the code very well, but if you''re expecting multiple rows, then wouldn''t I expect to find the Items.Add inside the loop(s)?

(I must have a different version of the listview control here, as it doesn''t even have .Items - it has .ListItems. So I may be talking complete garbage. :))



我对listview不太熟悉,所以不要我认真对待任何事情。但它看起来好像你在这些循环中所做的就是在一行中添加了许多子项(我认为相当于列)。


我并没有真正遵循代码,但如果你期望多行,那么我不期望在循环中找到 Items.Add 吗? />

(我必须在这里有一个不同版本的listview控件,因为它甚至没有 .Items - 它有 .ListItems 。所以我可能会说完全垃圾。:))
I''m not that familiar with the listview, so don''t take anything I say too seriously. But it looks to me as though all you''re doing in these loops is adding lots of subitems (which I believe are equivalent to "columns") into one row.

I didn''t really follow the code very well, but if you''re expecting multiple rows, then wouldn''t I expect to find the Items.Add inside the loop(s)?

(I must have a different version of the listview control here, as it doesn''t even have .Items - it has .ListItems. So I may be talking complete garbage. :))



好​​点。循环不添加任何新项。作业需要子项目,但你是对的。我需要一些能在循环中添加Items的东西。谢谢。这给了我一些现在可以使用的东西。我整个周末一直在盯着这段代码。你们很棒!


Good point. The loop is not adding any new Items. The assignment requires the subitems, but you are right. I need something that will add Items in the loop. Thanks. This gives me something to work with now. I have been staring at this code all weekend. You guys are great!



好​​点。循环不添加任何新项。作业需要子项目,但你是对的。我需要一些能在循环中添加Items的东西。谢谢。这给了我一些现在可以使用的东西。我整个周末一直在盯着这段代码。你们真棒!
Good point. The loop is not adding any new Items. The assignment requires the subitems, but you are right. I need something that will add Items in the loop. Thanks. This gives me something to work with now. I have been staring at this code all weekend. You guys are great!



BTW,


代码应该在listview的12'中生成乘法表。看起来应该是......


1 X 1 = 1

1 X 2 = 2

1 X 3 = 3

完成后应该有144个项目,只需按一下按钮即可填充。


BTW,

The code is supposed to produce the multiplication table throught the 12''s in the listview. It should look like this...

1 X 1 = 1
1 X 2 = 2
1 X 3 = 3

There should be 144 Items when it is finished, and it should all populate at the touch of one button.


这篇关于Listview:添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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