在.net 2010中循环计数列表视图中的数据 [英] Looping the data in listview with counted number in .net 2010
问题描述
大家好,
基于该主题,我已经访问了一些与我搜索将文本框中的数据添加到列表视图"有关的站点,并且打赌该步骤是可以接受的.但是现在,我想根据您在文本框中插入的数据量在listview中查看一个数字.我知道代码就像FOR xx到xxx ....下一步,但是详细编码,我无法编码.这是我访问的网站的代码示例.如果有人可以教,那是我的荣幸.
假设列表视图中有2个文本框但3列
第一栏:编号
第2栏:txt1
第三栏:txt2
原始代码示例:-
Hi all,
Based from the subject, I already visit some sites that relate to what I searching "Adding data from textbox to listview" and I bet that the step was acceptable. But right now, I want to view a number in listview based on how many data you inserted in textbox. I know the code was like FOR xx to xxx.... NEXT but the details coding, I failed to code. Here are the sample of code from site i visit. If someone can teach, it''s my pleasure.
Assume there are 2 textbox but 3 column in list view
Column 1st: Numbering
Column 2nd: txt1
Column 3rd: txt2
Sample of Original Code:-
dim li as new ListViewItem
li = ListView1.items.add(Textbox1.Text)
li.subitems.add(Textbox2.Text)
推荐答案
每次添加新项时,请使用:
Each time whe you add new item, use:
Dim lvi As System.Windows.Forms.ListViewItem = Nothing
Dim lvs1 As System.Windows.Forms.ListViewItem.ListViewSubItem = Nothing
Dim lvs2 As System.Windows.Forms.ListViewItem.ListViewSubItem = Nothing
Try
lvi = New System.Windows.Forms.ListViewItem(ListView1.Items.Count + 1)
lvs1 = New System.Windows.Forms.ListViewItem.ListViewSubItem(lvi, TextBox1.Text)
lvi.SubItems.Add(lvs1)
lvs2 = New System.Windows.Forms.ListViewItem.ListViewSubItem(lvi, TextBox2.Text)
lvi.SubItems.Add(lvs2)
ListView1.Items.Add(lvi)
ListView1.Refresh()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Finally
lvi = Nothing
lvs1 = Nothing
lvs2 = Nothing
End Try
好,您需要在ListView中添加列以反映子项并设置ListView.View = Details的属性.这是一个可以逐步帮助您的链接...
http://www.fryan0911.com/2009/06/vbnet- listview-tutorial-add-edit-and.html [ ^ ]
Well, you need to add columns in the ListView to reflect the subitems and set the property of the ListView.View=Details. Here is a link which can help you as a step by step guide...
http://www.fryan0911.com/2009/06/vbnet-listview-tutorial-add-edit-and.html[^]
这篇关于在.net 2010中循环计数列表视图中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!