473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding a listview item

Whilst looping through items in a listview I wish to have the option of
inserting a new row (in the middle not necessarily at the end of the
listview).

thus if lvw is the listview name

dim itm as listviewitem

For each itm in lvw.Items
'if certain condition is met then insert new row in the listview here
'row must be inserted immediately under the current item
next itm

Thanks
Gerry
Nov 21 '05 #1
2 2449
This does the trick:

Dim itm As listviewitem
Dim MaxItems As Integer = lvw.Items.Count - 1 '0-based
Dim Counter As Integer
Do While Counter <= MaxItems
itm = lvw.Items(Counter)
If CInt(itm.Text.Substring(4, 2)) / 2 = CInt(CInt(itm.Text.Substring(4,
2)) / 2) Then 'don't mind my "certain condition
'if certain condition is met then insert new row in the listview
here
'row must be inserted immediately under the current item
lvw.Items.Insert(itm.Index, New ListViewItem("New item"))
Counter += 1
MaxItems += 1
End If
Counter += 1
Loop

Hope this helps,
Stefan

"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
Whilst looping through items in a listview I wish to have the option of
inserting a new row (in the middle not necessarily at the end of the
listview).

thus if lvw is the listview name

dim itm as listviewitem

For each itm in lvw.Items
'if certain condition is met then insert new row in the listview here
'row must be inserted immediately under the current item
next itm

Thanks
Gerry

Nov 21 '05 #2
thanks

the line

lvw.Items.Insert(itm.Index, New ListViewItem("New item"))

was just what I was after.

Gerry

"Stefan De Schepper" wrote:
This does the trick:

Dim itm As listviewitem
Dim MaxItems As Integer = lvw.Items.Count - 1 '0-based
Dim Counter As Integer
Do While Counter <= MaxItems
itm = lvw.Items(Counter)
If CInt(itm.Text.Substring(4, 2)) / 2 = CInt(CInt(itm.Text.Substring(4,
2)) / 2) Then 'don't mind my "certain condition
'if certain condition is met then insert new row in the listview
here
'row must be inserted immediately under the current item
lvw.Items.Insert(itm.Index, New ListViewItem("New item"))
Counter += 1
MaxItems += 1
End If
Counter += 1
Loop

Hope this helps,
Stefan

"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
Whilst looping through items in a listview I wish to have the option of
inserting a new row (in the middle not necessarily at the end of the
listview).

thus if lvw is the listview name

dim itm as listviewitem

For each itm in lvw.Items
'if certain condition is met then insert new row in the listview here
'row must be inserted immediately under the current item
next itm

Thanks
Gerry


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Eva | last post by:
Hi, I wanted to know how i can enter values into a specific column of a listview. I have tried the following code but this seems to enter all my values into the first column!!! Can anyone...
1
by: J_Max | last post by:
Hello, This might be a really easy question, but... I am developing a simple Smart Device application that uses a listview. I have a function that adds a item to the listview - code is below. I...
2
by: Anushya devi | last post by:
Hi All I used listview and tried to update it by using Addrange. When the number of items is less, it works fine.. But I need to update nearly 200,000 items and it hangs. Also i need to add...
0
by: Andrew | last post by:
If item is a ListViewItem and str is a string, why do the following two lines not have the same effect ? item.SubItems.Add(new ListViewItem.ListViewSubItem()).Text = str;...
2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
3
by: Holmes | last post by:
Hello Ran into a bit of a problem here and have now exhausted my resources to getting this working What I am trying to do is load and show a simple vb form with a listbox in it Dim...
20
by: Ash Phillips | last post by:
Hi Everyone, I have this program I wrote in VB6 for family use. It's a DVD Database just for me to keep track of them cause I have so many lol. In VB6, I could add items to the ListView in...
9
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
6
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.