By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

Multiple List Views ?

P: n/a
Jm
Hi All

Is there a way to have multiple list views created during program runtime in
code, which can have objects added, removed and later on the listview itself
be removed, whilst keeping the previous listview(s) hidden or disabled under
the original ?

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Jm" <ja*****@ihug.com.au> schrieb:
Is there a way to have multiple list views created during program runtime
in
code, which can have objects added, removed and later on the listview
itself
be removed, whilst keeping the previous listview(s) hidden or disabled
under
the original ?


Yes, you can do that:

\\\
Dim i As Integer
For i = 1 To 10
Dim lvw As New ListView()
With lvw
.Location = ...
...
End With
Me.Controls.Add(lvw)
Next i
///

To add a handler to the listview controls' events, you can use
'AddHandler'/'RemoveHandler'. Inside the event handlers you can check the
'sender' parameter to get a reference to the listview control that raised
the event:

\\\
Dim SourceControl As ListView = DirectCast(sender, ListView)
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
JM,

Hefried mentioned the add and the use of the handlers however gave no code,
you can see this sample l although it is about buttons.

In this message is that sample from me of that.
http://groups-beta.google.com/group/...ead7b143e32591

I hope this helps?

Cor

Nov 21 '05 #3

P: n/a
Jm
Hi Cor

Thanks for quick reply. I checked out the site you said and ive got most of
the idea of it i think. But im doing something wrong with the coding of the
events. This is the code im using, excluding all code around it for ease of
copy and paste
Public SubLevelCount As Integer
Public SubLstView() As ListView
Public SubImgLst() As ImageList
Public Console As New frmMain
***

ReDim Preserve SubLstView(SubLevelCount)
ReDim Preserve SubImgLst(SubLevelCount)
SubLstView(SubLevelCount) = New ListView
SubImgLst(SubLevelCount) = New ImageList
SubImgLst(SubLevelCount).ImageSize = New Size(32, 32)
SubImgLst(SubLevelCount).Images.Add(Console.imgLst Main.Images(1))
SubLstView(SubLevelCount).Left = 8
SubLstView(SubLevelCount).Top = 32
SubLstView(SubLevelCount).Width = 560
SubLstView(SubLevelCount).Height = 224
SubLstView(SubLevelCount).BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView(SubLevelCount).ForeColor = System.Drawing.Color.White
SubLstView(SubLevelCount).MultiSelect = False
SubLstView(SubLevelCount).Parent = Console
SubLstView(SubLevelCount).Sorting = SortOrder.Ascending
SubLstView(SubLevelCount).SmallImageList = SubImgLst(SubLevelCount)
SubLstView(SubLevelCount).LargeImageList = SubImgLst(SubLevelCount)

Now heres where i wasnt sure how to go

SubLstView(SubLevelCount).Controls.Add(SubLstView( SubLevelCount))
AddHandler SubLstView(SubLevelCount).ItemActivate, AddressOf
SubLstView_ItemActivate
The addhandler line confused me. I wanted to add a handler for the item
activate event. So when a user double clicks i can run the necessary code. I
tried to adapt it to my code but at the end for the AddressOf part it seems
to fail and im not sure what to do from here ? Any Ideas ?

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:#P*************@TK2MSFTNGP11.phx.gbl...
JM,

Hefried mentioned the add and the use of the handlers however gave no code, you can see this sample l although it is about buttons.

In this message is that sample from me of that.
http://groups-beta.google.com/group/...ead7b143e32591
I hope this helps?

Cor

Nov 21 '05 #4

P: n/a
Jm
Little bit of extra info. I figured out the problem was me not reading the
google message further so i added the sub to handle the event with blank
code for the time being. But when the code gets to the point of adding the
control it gives me this message:

A circular control reference has been made. A control cannot be owned or
parented to itself

this is the extra code i added since last post

Public Sub Sublstview_ItemActivate(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim thisbutton As Button = DirectCast(sender, Button)
MessageBox.Show("The day is: " & thisbutton.Text)
End Sub
"Jm" <ja*****@ihug.com.au> wrote in message
news:cr*********@lust.ihug.co.nz...
Hi Cor

Thanks for quick reply. I checked out the site you said and ive got most of the idea of it i think. But im doing something wrong with the coding of the events. This is the code im using, excluding all code around it for ease of copy and paste
Public SubLevelCount As Integer
Public SubLstView() As ListView
Public SubImgLst() As ImageList
Public Console As New frmMain
***

ReDim Preserve SubLstView(SubLevelCount)
ReDim Preserve SubImgLst(SubLevelCount)
SubLstView(SubLevelCount) = New ListView
SubImgLst(SubLevelCount) = New ImageList
SubImgLst(SubLevelCount).ImageSize = New Size(32, 32)
SubImgLst(SubLevelCount).Images.Add(Console.imgLst Main.Images(1))
SubLstView(SubLevelCount).Left = 8
SubLstView(SubLevelCount).Top = 32
SubLstView(SubLevelCount).Width = 560
SubLstView(SubLevelCount).Height = 224
SubLstView(SubLevelCount).BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView(SubLevelCount).ForeColor = System.Drawing.Color.White
SubLstView(SubLevelCount).MultiSelect = False
SubLstView(SubLevelCount).Parent = Console
SubLstView(SubLevelCount).Sorting = SortOrder.Ascending
SubLstView(SubLevelCount).SmallImageList = SubImgLst(SubLevelCount)
SubLstView(SubLevelCount).LargeImageList = SubImgLst(SubLevelCount)

Now heres where i wasnt sure how to go

SubLstView(SubLevelCount).Controls.Add(SubLstView( SubLevelCount))
AddHandler SubLstView(SubLevelCount).ItemActivate, AddressOf
SubLstView_ItemActivate
The addhandler line confused me. I wanted to add a handler for the item
activate event. So when a user double clicks i can run the necessary code. I tried to adapt it to my code but at the end for the AddressOf part it seems to fail and im not sure what to do from here ? Any Ideas ?

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:#P*************@TK2MSFTNGP11.phx.gbl...
JM,

Hefried mentioned the add and the use of the handlers however gave no

code,
you can see this sample l although it is about buttons.

In this message is that sample from me of that.

http://groups-beta.google.com/group/...ead7b143e32591

I hope this helps?

Cor


Nov 21 '05 #5

P: n/a
Jm
Hi Cor

Sorry about the quick posts just figured out the problem, because im using
the code inside a module i cant use Me for

SubLstView(SubLevelCount).Controls.Add(SubLstView( SubLevelCount))

so instead i used the form that i was referencing in the code

Console.Controls.Add(SubLstView(SubLevelCount))

Thanks for the link, wouldnt have figured it out without it. So many thanks
once again

"Jm" <ja*****@ihug.com.au> wrote in message
news:cr**********@lust.ihug.co.nz...
Little bit of extra info. I figured out the problem was me not reading the
google message further so i added the sub to handle the event with blank
code for the time being. But when the code gets to the point of adding the
control it gives me this message:

A circular control reference has been made. A control cannot be owned or
parented to itself

this is the extra code i added since last post

Public Sub Sublstview_ItemActivate(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim thisbutton As Button = DirectCast(sender, Button)
MessageBox.Show("The day is: " & thisbutton.Text)
End Sub
"Jm" <ja*****@ihug.com.au> wrote in message
news:cr*********@lust.ihug.co.nz...
Hi Cor

Thanks for quick reply. I checked out the site you said and ive got most of
the idea of it i think. But im doing something wrong with the coding of

the
events. This is the code im using, excluding all code around it for ease

of
copy and paste
Public SubLevelCount As Integer
Public SubLstView() As ListView
Public SubImgLst() As ImageList
Public Console As New frmMain
***

ReDim Preserve SubLstView(SubLevelCount)
ReDim Preserve SubImgLst(SubLevelCount)
SubLstView(SubLevelCount) = New ListView
SubImgLst(SubLevelCount) = New ImageList
SubImgLst(SubLevelCount).ImageSize = New Size(32, 32)
SubImgLst(SubLevelCount).Images.Add(Console.imgLst Main.Images(1))
SubLstView(SubLevelCount).Left = 8
SubLstView(SubLevelCount).Top = 32
SubLstView(SubLevelCount).Width = 560
SubLstView(SubLevelCount).Height = 224
SubLstView(SubLevelCount).BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView(SubLevelCount).ForeColor = System.Drawing.Color.White
SubLstView(SubLevelCount).MultiSelect = False
SubLstView(SubLevelCount).Parent = Console
SubLstView(SubLevelCount).Sorting = SortOrder.Ascending
SubLstView(SubLevelCount).SmallImageList = SubImgLst(SubLevelCount)
SubLstView(SubLevelCount).LargeImageList = SubImgLst(SubLevelCount)

Now heres where i wasnt sure how to go

SubLstView(SubLevelCount).Controls.Add(SubLstView( SubLevelCount))
AddHandler SubLstView(SubLevelCount).ItemActivate, AddressOf
SubLstView_ItemActivate
The addhandler line confused me. I wanted to add a handler for the item
activate event. So when a user double clicks i can run the necessary

code. I
tried to adapt it to my code but at the end for the AddressOf part it

seems
to fail and im not sure what to do from here ? Any Ideas ?

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:#P*************@TK2MSFTNGP11.phx.gbl...
JM,

Hefried mentioned the add and the use of the handlers however gave no

code,
you can see this sample l although it is about buttons.

In this message is that sample from me of that.

http://groups-beta.google.com/group/...ead7b143e32591

I hope this helps?

Cor



Nov 21 '05 #6

P: n/a
JM,

Can you have a look from the sample I made from your code

You need for this to set a button in top of the form, I made as well your
listview a little bit smaller and used because of that the mouse down.

\\\\
Public SubLevelCount As Integer
Public SubImgLst() As ImageList
Friend myListViews As New ArrayList
Friend myListViewCount As Integer
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim SubLstView As New ListView
' SubImgLst = New ImageList
' SubImgLst.ImageSize = New Size(32, 32)
'SubImgLst.Images.Add(Console.imgLstMain.Images(1) )
SubLstView.Left = 8 + myListViewCount * 60
SubLstView.Top = 32
SubLstView.Width = 56
SubLstView.Height = 24
SubLstView.Name = (myListViewCount + 1).ToString
SubLstView.BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView.ForeColor = System.Drawing.Color.White
SubLstView.MultiSelect = False
' SubLstView.Parent = Console
SubLstView.Sorting = SortOrder.Ascending
' SubLstView.SmallImageList = SubImgLst
' SubLstView.LargeImageList = SubImgLst
myListViews.Add(SubLstView)
AddHandler SubLstView.MouseDown, AddressOf ListView_MouseDown
Me.Controls.Add(SubLstView)
myListViews.Add(SubLstView)
myListViewCount += 1
End Sub
Private Sub ListView_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs)
If myListViews.Count > 0 Then
Dim mylastlistview As ListView = _
DirectCast(myListViews(myListViews.Count - 1), ListView)
myListViews.RemoveAt(myListViews.Count - 1)
Me.Controls.Remove(mylastlistview)
myListViewCount -= 1
End If
End Sub
///

What is does is creating a listview when the button is clicked and removes
the last when there is a mouse down on whatever listview.

Is it alreayd 2005 there in NZ?
Than Happy newsyear

I hope this helps?

Cor
"Jm" <ja*****@ihug.com.au>
Hi Cor

Thanks for quick reply. I checked out the site you said and ive got most
of
the idea of it i think. But im doing something wrong with the coding of
the
events. This is the code im using, excluding all code around it for ease
of
copy and paste
Public SubLevelCount As Integer
Public SubLstView() As ListView
Public SubImgLst() As ImageList
Public Console As New frmMain
***

ReDim Preserve SubLstView(SubLevelCount)
ReDim Preserve SubImgLst(SubLevelCount)
SubLstView(SubLevelCount) = New ListView
SubImgLst(SubLevelCount) = New ImageList
SubImgLst(SubLevelCount).ImageSize = New Size(32, 32)
SubImgLst(SubLevelCount).Images.Add(Console.imgLst Main.Images(1))
SubLstView(SubLevelCount).Left = 8
SubLstView(SubLevelCount).Top = 32
SubLstView(SubLevelCount).Width = 560
SubLstView(SubLevelCount).Height = 224
SubLstView(SubLevelCount).BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView(SubLevelCount).ForeColor = System.Drawing.Color.White
SubLstView(SubLevelCount).MultiSelect = False
SubLstView(SubLevelCount).Parent = Console
SubLstView(SubLevelCount).Sorting = SortOrder.Ascending
SubLstView(SubLevelCount).SmallImageList = SubImgLst(SubLevelCount)
SubLstView(SubLevelCount).LargeImageList = SubImgLst(SubLevelCount)

Now heres where i wasnt sure how to go

SubLstView(SubLevelCount).Controls.Add(SubLstView( SubLevelCount))
AddHandler SubLstView(SubLevelCount).ItemActivate, AddressOf
SubLstView_ItemActivate
The addhandler line confused me. I wanted to add a handler for the item
activate event. So when a user double clicks i can run the necessary code.
I
tried to adapt it to my code but at the end for the AddressOf part it
seems
to fail and im not sure what to do from here ? Any Ideas ?

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:#P*************@TK2MSFTNGP11.phx.gbl...
JM,

Hefried mentioned the add and the use of the handlers however gave no

code,
you can see this sample l although it is about buttons.

In this message is that sample from me of that.

http://groups-beta.google.com/group/...ead7b143e32591

I hope this helps?

Cor


Nov 21 '05 #7

P: n/a
Jm
Hi Cor

Thankyou for the new code, havent seen a prob with it yet. And lol yes is it
NY here, only 30 mins ago, and not in Nz, in Aus(Sydney). For some reason my
isp's news server's all post out through NZ although it has one for each
state in aus for reading the mail. Happy new years to you :-)

"Cor Ligthert" <no************@planet.nl> wrote in message
news:#q**************@tk2msftngp13.phx.gbl...
JM,

Can you have a look from the sample I made from your code

You need for this to set a button in top of the form, I made as well your
listview a little bit smaller and used because of that the mouse down.

\\\\
Public SubLevelCount As Integer
Public SubImgLst() As ImageList
Friend myListViews As New ArrayList
Friend myListViewCount As Integer
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim SubLstView As New ListView
' SubImgLst = New ImageList
' SubImgLst.ImageSize = New Size(32, 32)
'SubImgLst.Images.Add(Console.imgLstMain.Images(1) )
SubLstView.Left = 8 + myListViewCount * 60
SubLstView.Top = 32
SubLstView.Width = 56
SubLstView.Height = 24
SubLstView.Name = (myListViewCount + 1).ToString
SubLstView.BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView.ForeColor = System.Drawing.Color.White
SubLstView.MultiSelect = False
' SubLstView.Parent = Console
SubLstView.Sorting = SortOrder.Ascending
' SubLstView.SmallImageList = SubImgLst
' SubLstView.LargeImageList = SubImgLst
myListViews.Add(SubLstView)
AddHandler SubLstView.MouseDown, AddressOf ListView_MouseDown
Me.Controls.Add(SubLstView)
myListViews.Add(SubLstView)
myListViewCount += 1
End Sub
Private Sub ListView_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs)
If myListViews.Count > 0 Then
Dim mylastlistview As ListView = _
DirectCast(myListViews(myListViews.Count - 1), ListView)
myListViews.RemoveAt(myListViews.Count - 1)
Me.Controls.Remove(mylastlistview)
myListViewCount -= 1
End If
End Sub
///

What is does is creating a listview when the button is clicked and removes
the last when there is a mouse down on whatever listview.

Is it alreayd 2005 there in NZ?
Than Happy newsyear

I hope this helps?

Cor
"Jm" <ja*****@ihug.com.au>
Hi Cor

Thanks for quick reply. I checked out the site you said and ive got most
of
the idea of it i think. But im doing something wrong with the coding of
the
events. This is the code im using, excluding all code around it for ease
of
copy and paste
Public SubLevelCount As Integer
Public SubLstView() As ListView
Public SubImgLst() As ImageList
Public Console As New frmMain
***

ReDim Preserve SubLstView(SubLevelCount)
ReDim Preserve SubImgLst(SubLevelCount)
SubLstView(SubLevelCount) = New ListView
SubImgLst(SubLevelCount) = New ImageList
SubImgLst(SubLevelCount).ImageSize = New Size(32, 32)
SubImgLst(SubLevelCount).Images.Add(Console.imgLst Main.Images(1))
SubLstView(SubLevelCount).Left = 8
SubLstView(SubLevelCount).Top = 32
SubLstView(SubLevelCount).Width = 560
SubLstView(SubLevelCount).Height = 224
SubLstView(SubLevelCount).BackColor = Drawing.Color.FromArgb(58, 110, 165)
SubLstView(SubLevelCount).ForeColor = System.Drawing.Color.White
SubLstView(SubLevelCount).MultiSelect = False
SubLstView(SubLevelCount).Parent = Console
SubLstView(SubLevelCount).Sorting = SortOrder.Ascending
SubLstView(SubLevelCount).SmallImageList = SubImgLst(SubLevelCount)
SubLstView(SubLevelCount).LargeImageList = SubImgLst(SubLevelCount)

Now heres where i wasnt sure how to go

SubLstView(SubLevelCount).Controls.Add(SubLstView( SubLevelCount))
AddHandler SubLstView(SubLevelCount).ItemActivate, AddressOf
SubLstView_ItemActivate
The addhandler line confused me. I wanted to add a handler for the item
activate event. So when a user double clicks i can run the necessary code. I
tried to adapt it to my code but at the end for the AddressOf part it
seems
to fail and im not sure what to do from here ? Any Ideas ?

Thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:#P*************@TK2MSFTNGP11.phx.gbl...
JM,

Hefried mentioned the add and the use of the handlers however gave no

code,
you can see this sample l although it is about buttons.

In this message is that sample from me of that.

http://groups-beta.google.com/group/...ead7b143e32591

I hope this helps?

Cor



Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.