PC Review


Reply
Thread Tools Rate Thread

ListView Help

 
 
samoore33
Guest
Posts: n/a
 
      7th Sep 2006
I found this code on MSDN, and it works great. It creates a ListView
dynamically and add items to it and all. It is great. I have changed a
few of the column names to suit me.

Dim listView1 As New ListView

listView1.Bounds = New Rectangle(New Point(10, 10), New
Size(300, 200))

' Set the view to show details.
listView1.View = View.Details
' Allow the user to edit item text.
listView1.LabelEdit = True
' Allow the user to rearrange columns.
listView1.AllowColumnReorder = True
' Display check boxes.
listView1.CheckBoxes = True
' Select the item and subitems when selection is made.
listView1.FullRowSelect = True
' Display grid lines.
listView1.GridLines = True
' Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending

' Create columns for the items and subitems.
listView1.Columns.Add("Item", -2, HorizontalAlignment.Left)
listView1.Columns.Add("State", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Flat", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Minimum", -2,
HorizontalAlignment.Center)
listView1.Columns.Add("Maximum", -2,
HorizontalAlignment.Center)
listView1.Columns.Add("Value", -2, HorizontalAlignment.Center)

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
'item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
'item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

'Add the items to the ListView.
listView1.Items.AddRange(New ListViewItem() {item1, item2,
item3})

MY ATTEMPT TO ADD THIS INFORMATION INTO A LISTVIEW ALREADY ON THE FORM
'lsvTest.Items.AddRange(New ListViewItem() {item1, item2,
item3})

' Add the ListView to the control collection.
Me.Controls.Add(listView1)

The problem is that I am trying to add information to a ListView that
is already a control on the form. It seems know matter what I try,
nothing will add to my listview. My unltimate goal is to add items from
a dataset to the listview. It does not seem to be an easy task to
complete, especially since the dataset has more then one table in it.

Any help would be appreciated.

Thanks.

Scott Moore

 
Reply With Quote
 
 
 
 
samoore33
Guest
Posts: n/a
 
      7th Sep 2006
As usual I was forgetting something, that is why I could not get any of
the information to show up in the ListView that I had added to the
form.

Now the fun part of figuring out how to add the information to the
listview. I think I know how to do that though, I should be able to
create a class that will help me add items to the listview.

Maybe I do not need a group, I just need someone to play like they are
listening to me while I think outloud.

Scott

samoore33 wrote:
> I found this code on MSDN, and it works great. It creates a ListView
> dynamically and add items to it and all. It is great. I have changed a
> few of the column names to suit me.
>
> Dim listView1 As New ListView
>
> listView1.Bounds = New Rectangle(New Point(10, 10), New
> Size(300, 200))
>
> ' Set the view to show details.
> listView1.View = View.Details
> ' Allow the user to edit item text.
> listView1.LabelEdit = True
> ' Allow the user to rearrange columns.
> listView1.AllowColumnReorder = True
> ' Display check boxes.
> listView1.CheckBoxes = True
> ' Select the item and subitems when selection is made.
> listView1.FullRowSelect = True
> ' Display grid lines.
> listView1.GridLines = True
> ' Sort the items in the list in ascending order.
> listView1.Sorting = SortOrder.Ascending
>
> ' Create columns for the items and subitems.
> listView1.Columns.Add("Item", -2, HorizontalAlignment.Left)
> listView1.Columns.Add("State", -2, HorizontalAlignment.Left)
> listView1.Columns.Add("Flat", -2, HorizontalAlignment.Left)
> listView1.Columns.Add("Minimum", -2,
> HorizontalAlignment.Center)
> listView1.Columns.Add("Maximum", -2,
> HorizontalAlignment.Center)
> listView1.Columns.Add("Value", -2, HorizontalAlignment.Center)
>
> ' Create three items and three sets of subitems for each item.
> Dim item1 As New ListViewItem("item1", 0)
> ' Place a check mark next to the item.
> 'item1.Checked = True
> item1.SubItems.Add("1")
> item1.SubItems.Add("2")
> item1.SubItems.Add("3")
> Dim item2 As New ListViewItem("item2", 1)
> item2.SubItems.Add("4")
> item2.SubItems.Add("5")
> item2.SubItems.Add("6")
> Dim item3 As New ListViewItem("item3", 0)
> ' Place a check mark next to the item.
> 'item3.Checked = True
> item3.SubItems.Add("7")
> item3.SubItems.Add("8")
> item3.SubItems.Add("9")
>
> 'Add the items to the ListView.
> listView1.Items.AddRange(New ListViewItem() {item1, item2,
> item3})
>
> MY ATTEMPT TO ADD THIS INFORMATION INTO A LISTVIEW ALREADY ON THE FORM
> 'lsvTest.Items.AddRange(New ListViewItem() {item1, item2,
> item3})
>
> ' Add the ListView to the control collection.
> Me.Controls.Add(listView1)
>
> The problem is that I am trying to add information to a ListView that
> is already a control on the form. It seems know matter what I try,
> nothing will add to my listview. My unltimate goal is to add items from
> a dataset to the listview. It does not seem to be an easy task to
> complete, especially since the dataset has more then one table in it.
>
> Any help would be appreciated.
>
> Thanks.
>
> Scott Moore


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB6 listview to VB 2005 listview - Help please Rita Microsoft VB .NET 0 21st Apr 2007 02:07 AM
PLZ Help, copy checked listview items to another listview Tim.Geiges@gmail.com Microsoft C# .NET 2 8th Jul 2006 04:59 PM
help coloring individual listview item instead of all listview item in visual c++ tonyck Webmaster / Programming 0 7th Jul 2006 11:06 AM
Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! -$- Windows XP Internet Explorer 2 21st Dec 2003 11:45 PM
RE: ListView - images disappear after coming back from another form with a ListView Armin Sadeghi [MSFT] Microsoft Dot NET Compact Framework 0 5th Sep 2003 11:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:29 PM.