在列表视图中添加行的问题 [英] Problem on adding rows in listview

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

问题描述

hi
我在具有值的列表视图中具有固定的行.现在,我想在同一列表视图中添加更多的行.

ListView

费用金额
AAA 120
BBB 120
CCC 120

事后我用以下几行在LV中添加了项目

hi
I''m having fixed rows in listview with values.. Now i want add some more rows in the same listview.

ListView

Expense Amount
AAA 120
BBB 120
CCC 120

Afte that i used this following lines to addd the items in LV

Dim lv4 As ListViewItem = lvexp.Items.Add(cb_exp.Text)
       lv4.SubItems.Add(txt_amt.Text)



我无法添加这些项目..帮帮我...



I can''t add the the items.. Hep Me......

推荐答案

此处给出了ListView 的示例http://msdn.microsoft.com/en-us/library/system.windows .forms.listview.listviewitemcollection.aspx#Y3100 [ ^ ]

在上面的示例中, two columns,与问题中指定的列数相似.

以下代码
An example on ListView is given here http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection.aspx#Y3100[^]

In the above example there are two columns, similar to the number of columns specified in the question.

The following code
Dim lv4 As ListViewItem = lvexp.Items.Add(cb_exp.Text)
lv4.SubItems.Add(txt_amt.Text)


ListView 中添加了另一行,没有任何错误.

请参见上面的示例.我认为这可能会有所帮助.


added another row in the ListView without any error.

Please see the above example. I think it may be helpful.


PunithaSabareeswari395,

您需要声明一个新对象,在这种情况下,是一个ListViewItem,它将保存必须添加到Listview中的所有数据,然后使用AddRange而不是Add将其添加到您的listview中.这是因为,如果仅使用添加",则仅传递一项,但如果使用添加范围",则可以传递任意数量的项

以下是解决您的问题的示例代码.



hi PunithaSabareeswari395,

You need to declare a new object, in this case, a ListViewItem that will hold all the data that has to be added in the Listview and then add it in your listview using AddRange and not Add. This is because, if you use Add only, you pass only one item but if you use AddRange, you can pass as many items as you want

Below is a sample code to solve your problem.



Dim mylists As New ListViewItem(New String() {cb_exp.Text}, -1)
        ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {mylists})
        ListView1.Focus()



只是尝试这个.希望对您有帮助! :)



Just try this. Hope it helps you! :)


这篇关于在列表视图中添加行的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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