473,804 Members | 3,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListViewItems from array


lvProjects.Clea r()
lvProjects.View = View.Details
lvProjects.Full RowSelect = True
lvProjects.Colu mns.Add("Id", 50, HorizontalAlign ment.Left)
lvProjects.Colu mns.Add("Name", -1, HorizontalAlign ment.Left)
lvProjects.Colu mns.Add("Last Used", 100, HorizontalAlign ment.Center)
lvProjects.Colu mns.Add("Status ", 100, HorizontalAlign ment.Center)
Dim Item1 As New ListViewItem("0 01", 0)
Item1.SubItems. Add("ABC Soliciters")
Item1.SubItems. Add("12/01/2003")
Item1.SubItems. Add("Idle")
Dim Item2 As New ListViewItem("0 02", 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.Item s.AddRange(New ListViewItem() {how do i assign al here})

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

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

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

Regards,
Fergus
Nov 20 '05 #2
* "Fergus Cooney" <fi****@post.co m> scripsit:
Have you tried simply:
lvProjects.Item s.AddRange (al)
or
lvProjects.Item s.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.co m> 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.Item s.AddRange (al.ToArray (GetType (ListViewItem)) )

With Option Strict On:
Dim ao As Array = al.ToArray (GetType (ListViewItem))
lvProjects.Item s.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.Item s.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.co m> wrote in message
news:OX******** ******@TK2MSFTN GP10.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.Item s.AddRange (al.ToArray (GetType (ListViewItem)) )

With Option Strict On:
Dim ao As Array = al.ToArray (GetType (ListViewItem))
lvProjects.Item s.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.Item s.AddRange (alvItems)
Regards,
Fergus

Nov 20 '05 #7
* "Chad Miller" <ch**@predictiv econcepts.com> scripsit:
lvProjects.Clea r()
lvProjects.View = View.Details
lvProjects.Full RowSelect = True
lvProjects.Colu mns.Add("Id", 50, HorizontalAlign ment.Left)
lvProjects.Colu mns.Add("Name", -1, HorizontalAlign ment.Left)
lvProjects.Colu mns.Add("Last Used", 100, HorizontalAlign ment.Center)
lvProjects.Colu mns.Add("Status ", 100, HorizontalAlign ment.Center)
Dim Item1 As New ListViewItem("0 01", 0)
Item1.SubItems. Add("ABC Soliciters")
Item1.SubItems. Add("12/01/2003")
Item1.SubItems. Add("Idle")
Dim Item2 As New ListViewItem("0 02", 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.Item s.AddRange(New ListViewItem() {how do i assign al here})

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


\\\
Dim al As New ArrayList
al.Add(New ListViewItem("H ello"))
al.Add(New ListViewItem("W orld"))
Me.ListView1.It ems.AddRange(Di rectCast(al.ToA rray(GetType(Li stViewItem)), 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.Colu mns.Add("Name", -1, HorizontalAlign ment.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.Colu mns(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.SetWidth ToFit 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
2783
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
575
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 print_r cmd any suggestions would be great. Thanks much Todd //avShed array Array ( => Array ( => 1 => 08:00 ) => Array ( => 1 => 08:05 ) => Array ( => 1 => 08:10 ) => Array ( => 1 => 08:15 ) => Array ( => 1 => 08:20 ) => Array...
15
5196
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
3484
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( "name", "title", "reports to user id", "start date in the format: mm/dd/yyyy" ) ); How can I display this hierarchy in simple nested <li> tags in the most
12
55574
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 also removed) So far I have (val is value, ar is array, returns new array):
8
10235
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 it is assigned a text literal?? HOW can I change the array value to upper case then? What other method exists for arrays? Ex: var GridArrayName1 = new Array(); GridArrayName1 = new Array ('test-value'); GridArrayName1 = GridArrayName1...
58
10188
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 code... TCHAR myArray; DoStuff(myArray);
2
1751
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 selected in a ComboBox. I have written a procedure that reads the ComboBox selected item and populates the ListView according to that. The procedure uses a "for" cycle: in every iteration it creates a ListViewItem, set its SubItems and BackColor...
1
2641
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?
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.