473,378 Members | 1,421 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,378 software developers and data experts.

ListViewItems from array


lvProjects.Clear()
lvProjects.View = View.Details
lvProjects.FullRowSelect = True
lvProjects.Columns.Add("Id", 50, HorizontalAlignment.Left)
lvProjects.Columns.Add("Name", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Last Used", 100, HorizontalAlignment.Center)
lvProjects.Columns.Add("Status", 100, HorizontalAlignment.Center)
Dim Item1 As New ListViewItem("001", 0)
Item1.SubItems.Add("ABC Soliciters")
Item1.SubItems.Add("12/01/2003")
Item1.SubItems.Add("Idle")
Dim Item2 As New ListViewItem("002", 0)
Item2.SubItems.Add("ABC Soliciters")
Item2.SubItems.Add("12/01/2002")
Item2.SubItems.Add("Idle")
Dim al As New ArrayList()
al.Add(Item1)
al.Add(Item2)

Question: How do I assign al to in the following line?
lvProjects.Items.AddRange(New ListViewItem() {how do i assign al here})

This works below:
lvProjects.Items.AddRange(New ListViewItem() {item1,item2})

Thanks 4 any help!!
Nov 20 '05 #1
8 9005
Hi Chad,

Have you tried simply:
lvProjects.Items.AddRange (al)
or
lvProjects.Items.AddRange (al.ToArray)

Regards,
Fergus
Nov 20 '05 #2
* "Fergus Cooney" <fi****@post.com> scripsit:
Have you tried simply:
lvProjects.Items.AddRange (al)
or
lvProjects.Items.AddRange (al.ToArray)


Have you tried that?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #3
Why do you ask?
Nov 20 '05 #4
* "Fergus Cooney" <fi****@post.com> scripsit:
Why do you ask?


Try it and you will see it...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #5
Hi Chad,

The second option in my earlier post is the one you want but it needed a
bit of casting:

With Option Strict Off:
lvProjects.Items.AddRange (al.ToArray (GetType (ListViewItem)))

With Option Strict On:
Dim ao As Array = al.ToArray (GetType (ListViewItem))
lvProjects.Items.AddRange (DirectCast (ao, ListViewItem()))

But it might be easier to assign the ListViewItems to an array of a
suitable type in the first place.
Dim alv As ListViewItem (1)
alvItems(0) = Item1
alvItems(1) = Item2
lvProjects.Items.AddRange (alvItems)
Regards,
Fergus
Nov 20 '05 #6
Thanks, that is what I ended up doing (using an array). Sometimes its nice
to use the arraylist not to worry about array length. Thanks again!!!

One other thing .. If you populate the listview with column size property
to -1 for auto resize the first time it is populated using the method we
have discussed it works fine. But each time after that it sets the column
length to 0. Any ideas why?

"Fergus Cooney" <fi****@post.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
Hi Chad,

The second option in my earlier post is the one you want but it needed a bit of casting:

With Option Strict Off:
lvProjects.Items.AddRange (al.ToArray (GetType (ListViewItem)))

With Option Strict On:
Dim ao As Array = al.ToArray (GetType (ListViewItem))
lvProjects.Items.AddRange (DirectCast (ao, ListViewItem()))

But it might be easier to assign the ListViewItems to an array of a
suitable type in the first place.
Dim alv As ListViewItem (1)
alvItems(0) = Item1
alvItems(1) = Item2
lvProjects.Items.AddRange (alvItems)
Regards,
Fergus

Nov 20 '05 #7
* "Chad Miller" <ch**@predictiveconcepts.com> scripsit:
lvProjects.Clear()
lvProjects.View = View.Details
lvProjects.FullRowSelect = True
lvProjects.Columns.Add("Id", 50, HorizontalAlignment.Left)
lvProjects.Columns.Add("Name", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Last Used", 100, HorizontalAlignment.Center)
lvProjects.Columns.Add("Status", 100, HorizontalAlignment.Center)
Dim Item1 As New ListViewItem("001", 0)
Item1.SubItems.Add("ABC Soliciters")
Item1.SubItems.Add("12/01/2003")
Item1.SubItems.Add("Idle")
Dim Item2 As New ListViewItem("002", 0)
Item2.SubItems.Add("ABC Soliciters")
Item2.SubItems.Add("12/01/2002")
Item2.SubItems.Add("Idle")
Dim al As New ArrayList()
al.Add(Item1)
al.Add(Item2)

Question: How do I assign al to in the following line?
lvProjects.Items.AddRange(New ListViewItem() {how do i assign al here})

This works below:
lvProjects.Items.AddRange(New ListViewItem() {item1,item2})


\\\
Dim al As New ArrayList
al.Add(New ListViewItem("Hello"))
al.Add(New ListViewItem("World"))
Me.ListView1.Items.AddRange(DirectCast(al.ToArray( GetType(ListViewItem)), ListViewItem()))
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #8
Hi Chad,

That Column.Width = -1 is a bit misleading in the sense that if you set
the Width to -1 when you create it,
lvProjects.Columns.Add("Name", -1, HorizontalAlignment.Left)
it sets the width to zero because there are no items, therefore the
greatest width = 0.

It's really for use when you've got your items in place. So if you add

lvProjects.Columns(1).Width = -1
after the items have been added, it will work ok.

And you'll have to keep setting it when you add items or remove items
because it's not a dynamic setting. It would be better, in fact, if they had
a method Column.SetWidthToFit or something. This would make it clear that
you have to keep doing it. For .NET, using Width = -1 seems a pretty kludgy
way of doing it.

Regards,
Fergus
Nov 20 '05 #9

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

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: polocar | last post by:
Hello, I'm developing a C# program using Visual Studio 2005 Professional Edition. In the main form I have inserted a ListView control that is populated in a different way depending on the item...
1
by: =?Utf-8?B?VmljdG9y?= | last post by:
Hi, How to get a list of ListViewItems that are currently shown in a Windows Form ListView control when that that control is in a virtual mode?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.