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

Adding Items to ListView through another form

P: n/a
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 'frmMain' from 'frmAdd' with
the following code:

Private Function AddEntry(Title As String, Rating As String, Genre As
String, OnLoan As Boolean, ToWho As String)
Dim x As ListItem

Set x = frmMain.lvwDVD.ListItems.Add(, , Title, , 1)
x.SubItems(1) = Rating
x.SubItems(2) = Genre
If OnLoan = True Then
x.SubItems(3) = "Yes"
Else
x.SubItems(3) = "No"
End If
x.SubItems(4) = ToWho

frmMain.lvwDVD.SelectedItem = x

End Function

The ListView I use in VB6 is from COMCTL.OCX

Now in VB .NET I have the following:

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim frmMain As New frmMain
Dim X As ListViewItem

X = frmmain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

The ListView I use in VB .NET is the System.Windows.Forms.ListView (I
believe)

In VB6, 'frmAdd' would be shown modal above 'frmMain' and the function would
add the item succesfully to the ListView.

For the life of me I can't make this happen in VB .NET :(

Is it at all possible?

Thanks in advance,
Ash
Nov 21 '05 #1
Share this Question
Share on Google+
20 Replies


P: n/a
> Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim frmMain As New frmMain For the life of me I can't make this happen in VB .NET :(
That's because in the above line of code you are creating a new instance of
frmMain and you're adding the listview item to this new form - not to the
instance of frmMain that you have opened already. What you need is a
reference to the original frmMain that is opened. There are several ways you
can do that. One way is you can pass a reference to frmMain to frmAdd
through frmAdd's constructor. Either use the same constructor or just add
another one which takes in a reference to frmMain. Here's some code:

' This is in frmMain
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Here we pass the frmMain reference to frmAdd
Dim ofrmAdd As New frmAdd(Me)
ofrmAdd.ShowDialog()
End Sub
' This is in frmAdd
Private ofrmMain As frmMain

' Either change the exisiting Sub New or just add this one.
' Both ways will work just fine.
Public Sub New(ByRef oMain As Form1)
MyBase.New()
InitializeComponent()
ofrmMain = oMain
End Sub

' Now add your listview items using this instance of frmMain
Private Function AddEntry(ByVal Title As String, _
ByVal Rating As String, ByVal Genre As String, _
ByVal OnLoan As Boolean, ByVal ToWho As String)

Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

I hope that helps a bit..
Imran.
Is it at all possible?

Nov 21 '05 #2

P: n/a
> Public Sub New(ByRef oMain As Form1)

Sorry - the above line should be:
Public Sub New(ByRef oMain As frmMain)

you'd have figured that out though :)

Imran.
Nov 21 '05 #3

P: n/a
Hi Imran, thanks for your help.

I have done all that you said, and triple checked it lol

When I press the Add button in frmAdd, it still brings up a new instance of
frmMain but for some reason the Item hasnt even been added there?

Any other suggestions?

Ash

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim frmMain As New frmMain
For the life of me I can't make this happen in VB .NET :(


That's because in the above line of code you are creating a new instance

of frmMain and you're adding the listview item to this new form - not to the
instance of frmMain that you have opened already. What you need is a
reference to the original frmMain that is opened. There are several ways you can do that. One way is you can pass a reference to frmMain to frmAdd
through frmAdd's constructor. Either use the same constructor or just add
another one which takes in a reference to frmMain. Here's some code:

' This is in frmMain
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Here we pass the frmMain reference to frmAdd
Dim ofrmAdd As New frmAdd(Me)
ofrmAdd.ShowDialog()
End Sub
' This is in frmAdd
Private ofrmMain As frmMain

' Either change the exisiting Sub New or just add this one.
' Both ways will work just fine.
Public Sub New(ByRef oMain As Form1)
MyBase.New()
InitializeComponent()
ofrmMain = oMain
End Sub

' Now add your listview items using this instance of frmMain
Private Function AddEntry(ByVal Title As String, _
ByVal Rating As String, ByVal Genre As String, _
ByVal OnLoan As Boolean, ByVal ToWho As String)

Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

I hope that helps a bit..
Imran.
Is it at all possible?


Nov 21 '05 #4

P: n/a
Strange. I tried the same thing on my machine and it works fine. Can you
post the exact code that you now have? Maybe that'll help us figure out what
exactly is going on.

Imran.

"Ash Phillips" <as*@expwin.net> wrote in message
news:ez*************@TK2MSFTNGP14.phx.gbl...
Hi Imran, thanks for your help.

I have done all that you said, and triple checked it lol

When I press the Add button in frmAdd, it still brings up a new instance
of
frmMain but for some reason the Item hasnt even been added there?

Any other suggestions?

Ash

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Private Function AddEntry(ByVal Title As String, ByVal Rating As
> String,
> ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
> Dim frmMain As New frmMain

> For the life of me I can't make this happen in VB .NET :(


That's because in the above line of code you are creating a new instance

of
frmMain and you're adding the listview item to this new form - not to the
instance of frmMain that you have opened already. What you need is a
reference to the original frmMain that is opened. There are several ways

you
can do that. One way is you can pass a reference to frmMain to frmAdd
through frmAdd's constructor. Either use the same constructor or just add
another one which takes in a reference to frmMain. Here's some code:

' This is in frmMain
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Here we pass the frmMain reference to frmAdd
Dim ofrmAdd As New frmAdd(Me)
ofrmAdd.ShowDialog()
End Sub
' This is in frmAdd
Private ofrmMain As frmMain

' Either change the exisiting Sub New or just add this one.
' Both ways will work just fine.
Public Sub New(ByRef oMain As Form1)
MyBase.New()
InitializeComponent()
ofrmMain = oMain
End Sub

' Now add your listview items using this instance of frmMain
Private Function AddEntry(ByVal Title As String, _
ByVal Rating As String, ByVal Genre As String, _
ByVal OnLoan As Boolean, ByVal ToWho As String)

Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

I hope that helps a bit..
Imran.
> Is it at all possible?



Nov 21 '05 #5

P: n/a
i still have same problem. but i'm using irc chat similar to mirc

Ash Phillips wrote:
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 'frmMain' from 'frmAdd' with
the following code:

Private Function AddEntry(Title As String, Rating As String, Genre As
String, OnLoan As Boolean, ToWho As String)
Dim x As ListItem

Set x = frmMain.lvwDVD.ListItems.Add(, , Title, , 1)
x.SubItems(1) = Rating
x.SubItems(2) = Genre
If OnLoan = True Then
x.SubItems(3) = "Yes"
Else
x.SubItems(3) = "No"
End If
x.SubItems(4) = ToWho

frmMain.lvwDVD.SelectedItem = x

End Function

The ListView I use in VB6 is from COMCTL.OCX

Now in VB .NET I have the following:

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim frmMain As New frmMain
Dim X As ListViewItem

X = frmmain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

The ListView I use in VB .NET is the System.Windows.Forms.ListView (I
believe)

In VB6, 'frmAdd' would be shown modal above 'frmMain' and the function would
add the item succesfully to the ListView.

For the life of me I can't make this happen in VB .NET :(

Is it at all possible?

Thanks in advance,
Ash


Nov 21 '05 #6

P: n/a
On Sun, 12 Sep 2004 12:42:00 +0100, Ash Phillips wrote:
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 'frmMain' from 'frmAdd' with
the following code:

Private Function AddEntry(Title As String, Rating As String, Genre As
String, OnLoan As Boolean, ToWho As String)
Dim x As ListItem

Set x = frmMain.lvwDVD.ListItems.Add(, , Title, , 1)
x.SubItems(1) = Rating
x.SubItems(2) = Genre
If OnLoan = True Then
x.SubItems(3) = "Yes"
Else
x.SubItems(3) = "No"
End If
x.SubItems(4) = ToWho

frmMain.lvwDVD.SelectedItem = x

End Function

The ListView I use in VB6 is from COMCTL.OCX

Now in VB .NET I have the following:

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim frmMain As New frmMain
Dim X As ListViewItem

X = frmmain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

The ListView I use in VB .NET is the System.Windows.Forms.ListView (I
believe)

In VB6, 'frmAdd' would be shown modal above 'frmMain' and the function would
add the item succesfully to the ListView.

For the life of me I can't make this happen in VB .NET :(

Is it at all possible?

Thanks in advance,
Ash


You have a couple of choices, make a propertie on the second form that
retuns a new listviewitem that can be added to your form... You would
probably have a button that returns DialogResult.Ok - so that in the main
form you could do:

Dim dialogForm As New FormB
If dialogForm.ShowDialog (Me) = DialogResult.Ok Then
Me.ListView1.Items.Add (dialogForm.NewItem)
End If
so in the dialog form, you would just add a property that looked like
Private NewListViewItem As New ListViewItem

....

' populate the listviewitem

Public ReadOnly Property NewItem As ListViewItem
Get
Return Me.NewListViewItem
End Get
End Property

Or, you could just have a second constructor on your dialog form that takes
a reference to the listview control that you want to add to...

Sub New (ByVal listview1 as ListView)
me.listview1 = listview1
end sub

' populate the list view..

HTH
--
Tom Shelton [MVP]
Nov 21 '05 #7

P: n/a
Sorry for the delayed response

In frmAdd, I have:
Public Sub New(ByRef oMain As frmMain)

MyBase.New()

InitializeComponent()

ofrmMain = oMain

End Sub

------------------

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)

Dim frmMain As New frmMain

Dim X As ListViewItem

X = frmMain.lvwDVD.Items.Add(Title)

X.SubItems(1).Text = Rating

X.SubItems(2).Text = Genre

If OnLoan = True Then

X.SubItems(3).Text = "Yes"

Else

X.SubItems(3).Text = "No"

End If

X.SubItems(4).Text = ToWho

End Function

------------------------

Private Sub butAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butAdd.Click

On Error Resume Next

AddEntry(txtTitle.Text, cboRating.Text, cboGenre.Text, optYes.Checked,
txtLoan.Text)

End Sub

In frmMain I have liek you told me:

"Imran Koradia" <no****@microsoft.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...
Strange. I tried the same thing on my machine and it works fine. Can you
post the exact code that you now have? Maybe that'll help us figure out what exactly is going on.

Imran.

"Ash Phillips" <as*@expwin.net> wrote in message
news:ez*************@TK2MSFTNGP14.phx.gbl...
Hi Imran, thanks for your help.

I have done all that you said, and triple checked it lol

When I press the Add button in frmAdd, it still brings up a new instance
of
frmMain but for some reason the Item hasnt even been added there?

Any other suggestions?

Ash

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Private Function AddEntry(ByVal Title As String, ByVal Rating As
> String,
> ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String) > Dim frmMain As New frmMain

> For the life of me I can't make this happen in VB .NET :(

That's because in the above line of code you are creating a new instance
of
frmMain and you're adding the listview item to this new form - not to
the instance of frmMain that you have opened already. What you need is a
reference to the original frmMain that is opened. There are several ways you
can do that. One way is you can pass a reference to frmMain to frmAdd
through frmAdd's constructor. Either use the same constructor or just

add another one which takes in a reference to frmMain. Here's some code:

' This is in frmMain
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Here we pass the frmMain reference to frmAdd
Dim ofrmAdd As New frmAdd(Me)
ofrmAdd.ShowDialog()
End Sub
' This is in frmAdd
Private ofrmMain As frmMain

' Either change the exisiting Sub New or just add this one.
' Both ways will work just fine.
Public Sub New(ByRef oMain As Form1)
MyBase.New()
InitializeComponent()
ofrmMain = oMain
End Sub

' Now add your listview items using this instance of frmMain
Private Function AddEntry(ByVal Title As String, _
ByVal Rating As String, ByVal Genre As String, _
ByVal OnLoan As Boolean, ByVal ToWho As String)

Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

End Function

I hope that helps a bit..
Imran.

> Is it at all possible?



Nov 21 '05 #8

P: n/a
Here's what I have in frmAdd:

Public Sub New(ByRef oMain As frmMain)
MyBase.New()
InitializeComponent()
ofrmMain = oMain
End Sub

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim frmMain As New frmMain
Dim X As ListViewItem

X = frmMain.lvwDVD.Items.Add(Title)
'X = frmMain.lvwDVD.ListItems.Add(, , Title, , 1)
X.SubItems(1).ForeColor = System.Drawing.Color.Red
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

' frmmain.lvwDVD.Items.Item =

End Function

Private Sub butAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butAdd.Click
AddEntry(txtTitle.Text, cboRating.Text, cboGenre.Text,
optYes.Checked, txtLoan.Text)
End Sub

And in frmMain I have the following like you told me:

Private Sub mnu_Add_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu_Add.Click
Dim ofrmAdd As New frmAdd(Me)
ofrmAdd.ShowDialog()
End Sub

Sorry for the delayed response!
Nov 21 '05 #9

P: n/a
> Private Function AddEntry(ByVal Title As String, ByVal Rating As
String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
-----> Dim frmMain As New frmMain
This is the problem. You're still creating a new instance of frmMain and
using this instance in the code below. You should use the existing instance
of frmMain that you passed in the constructor of this form. Replace
'frmMain' wherever its being used in the code below with 'ofrmMain' since
that is the existing instance of your main form. You should be fine then.
Dim X As ListViewItem

X = frmMain.lvwDVD.Items.Add(Title)
'X = frmMain.lvwDVD.ListItems.Add(, , Title, , 1)
X.SubItems(1).ForeColor = System.Drawing.Color.Red
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

' frmmain.lvwDVD.Items.Item =

End Function
Sorry for the delayed response!

Not a problem :) Actually, I'm a little late too ;-)

hope that helps..
Imran.
Nov 21 '05 #10

P: n/a
THanks for the reply - I am getting somewhere now!!!

However in my AddEntry function I get the error:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred
in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid
values.

and it highlights the line:

X.SubItems(1).Text = Rating

Any ideas?

Thanks again,
Ash

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)


-----> Dim frmMain As New frmMain
This is the problem. You're still creating a new instance of frmMain and
using this instance in the code below. You should use the existing

instance of frmMain that you passed in the constructor of this form. Replace
'frmMain' wherever its being used in the code below with 'ofrmMain' since
that is the existing instance of your main form. You should be fine then.
Dim X As ListViewItem

X = frmMain.lvwDVD.Items.Add(Title)
'X = frmMain.lvwDVD.ListItems.Add(, , Title, , 1)
X.SubItems(1).ForeColor = System.Drawing.Color.Red
X.SubItems(1).Text = Rating
X.SubItems(2).Text = Genre
If OnLoan = True Then
X.SubItems(3).Text = "Yes"
Else
X.SubItems(3).Text = "No"
End If
X.SubItems(4).Text = ToWho

' frmmain.lvwDVD.Items.Item =

End Function


Sorry for the delayed response!

Not a problem :) Actually, I'm a little late too ;-)

hope that helps..
Imran.

Nov 21 '05 #11

P: n/a
> and it highlights the line:

X.SubItems(1).Text = Rating


you haven't added the subitem yet which is why you get the error. You need
to do SubItems.Add just like you did Items.Add. This is how your code should
look like:
(watch for typos - i'm writing the code directly in this message)

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
With X
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With

End Function

That should pretty much solve the error you mentioned. Ofcourse, once you've
added the subitems, you can reference them with the index - for instance,
the Rating subitem with index 1 and so on..

hope that helps..
Imran.
Nov 21 '05 #12

P: n/a
ahhh thank you very much - I will try it now and let you know how it goes!!

I saw the add property but didnt think that'd be it - so used to VB6 :'(

Ash

"Imran Koradia" <no****@microsoft.com> wrote in message
news:u0*************@tk2msftngp13.phx.gbl...
and it highlights the line:

X.SubItems(1).Text = Rating
you haven't added the subitem yet which is why you get the error. You need
to do SubItems.Add just like you did Items.Add. This is how your code

should look like:
(watch for typos - i'm writing the code directly in this message)

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
With X
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With

End Function

That should pretty much solve the error you mentioned. Ofcourse, once you've added the subitems, you can reference them with the index - for instance,
the Rating subitem with index 1 and so on..

hope that helps..
Imran.

Nov 21 '05 #13

P: n/a
hmmmmmm the forecolor doesnt work on the subitem for me... does it work for
you?
"Imran Koradia" <no****@microsoft.com> wrote in message
news:u0*************@tk2msftngp13.phx.gbl...
and it highlights the line:

X.SubItems(1).Text = Rating
you haven't added the subitem yet which is why you get the error. You need
to do SubItems.Add just like you did Items.Add. This is how your code

should look like:
(watch for typos - i'm writing the code directly in this message)

Private Function AddEntry(ByVal Title As String, ByVal Rating As String,
ByVal Genre As String, ByVal OnLoan As Boolean, ByVal ToWho As String)
Dim X As ListViewItem

X = ofrmMain.lvwDVD.Items.Add(Title)
With X
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With

End Function

That should pretty much solve the error you mentioned. Ofcourse, once you've added the subitems, you can reference them with the index - for instance,
the Rating subitem with index 1 and so on..

hope that helps..
Imran.

Nov 21 '05 #14

P: n/a
Ok, I have another problem :(

With ofrmMain.lvwDVD.Items
For Y = 0 To .Count

If UCase(.Item(Y).Text) = UCase(txtTitle.Text) Then

MsgBox("The item '" & txtTitle.Text & "' is already added to the Database."
& vbCrLf & "To allow Duplicate Entries to the Database, please go to
Options.", vbCritical + vbOKOnly, "Database - Duplicate Entry")

txtTitle.Focus()

txtTitle.SelectionStart = 0

txtTitle.SelectionLength = Len(txtTitle.Text)

Exit Sub

End If

Next Y

End With

Basically, I want it to search through all items in the listview to check
for duplicate entries, but for some reason it higlights the line

If UCase(.Item(Y).Text) = UCase(txtTitle.Text) Then

And gives the following error:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred
in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid
values.
Ash
"Ash Phillips" <as*@expwin.net> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
Thanks - that worked great!

Ash

"Imran Koradia" <Imran Ko*****@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com...
hmmmmmm the forecolor doesnt work on the subitem for me... does it
work
for you?


set the 'UseItemStyleForSubItems' of the ListItem to false before adding

any
of the subitems.

With X
' add this so that style of the listitem is NOT
' used for all the subitems.
.UseItemStyleForSubItems = False
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With


Nov 21 '05 #15

P: n/a
Thanks - that worked great!

Ash

"Imran Koradia" <Imran Ko*****@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com...
hmmmmmm the forecolor doesnt work on the subitem for me... does it work for you?

set the 'UseItemStyleForSubItems' of the ListItem to false before adding

any of the subitems.

With X
' add this so that style of the listitem is NOT
' used for all the subitems.
.UseItemStyleForSubItems = False
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With

Nov 21 '05 #16

P: n/a
hey Ash,

Sorry for the late reply - I thought that was the end of this thread :-)

Anyway - you need to have your counter from 0 to .Count - 1 because although
the number of items is .Count, the index ranges from 0 to .Count - 1.

hope that helps..
Imran.

"Ash Phillips" <as*@expwin.net> wrote in message
news:eY**************@TK2MSFTNGP15.phx.gbl...
Ok, I have another problem :(

With ofrmMain.lvwDVD.Items
For Y = 0 To .Count

If UCase(.Item(Y).Text) = UCase(txtTitle.Text) Then

MsgBox("The item '" & txtTitle.Text & "' is already added to the Database." & vbCrLf & "To allow Duplicate Entries to the Database, please go to
Options.", vbCritical + vbOKOnly, "Database - Duplicate Entry")

txtTitle.Focus()

txtTitle.SelectionStart = 0

txtTitle.SelectionLength = Len(txtTitle.Text)

Exit Sub

End If

Next Y

End With

Basically, I want it to search through all items in the listview to check
for duplicate entries, but for some reason it higlights the line

If UCase(.Item(Y).Text) = UCase(txtTitle.Text) Then

And gives the following error:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid
values.
Ash
"Ash Phillips" <as*@expwin.net> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
Thanks - that worked great!

Ash

"Imran Koradia" <Imran Ko*****@discussions.microsoft.com> wrote in message news:99**********************************@microsof t.com...

> hmmmmmm the forecolor doesnt work on the subitem for me... does it work
for
> you?
>

set the 'UseItemStyleForSubItems' of the ListItem to false before

adding any
of the subitems.

With X
' add this so that style of the listitem is NOT
' used for all the subitems.
.UseItemStyleForSubItems = False
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With



Nov 21 '05 #17

P: n/a
> I saw the add property but didnt think that'd be it - so used to VB6 :'(
...same here. But you'll get used to it to the extent that you'll never
want to go back to VB6 since VB .NET is so much better. And VB 2005 is
even better :)

Imran.

Nov 21 '05 #18

P: n/a
hmmmmmm the forecolor doesnt work on the subitem for me... does it work for
you?


set the 'UseItemStyleForSubItems' of the ListItem to false before adding any
of the subitems.

With X
' add this so that style of the listitem is NOT
' used for all the subitems.
.UseItemStyleForSubItems = False
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With

Nov 21 '05 #19

P: n/a
> I saw the add property but didnt think that'd be it - so used to VB6 :'(
...same here. But you'll get used to it to the extent that you'll never
want to go back to VB6 since VB .NET is so much better. And VB 2005 is
even better :)

Imran.

Nov 21 '05 #20

P: n/a
hmmmmmm the forecolor doesnt work on the subitem for me... does it work for
you?


set the 'UseItemStyleForSubItems' of the ListItem to false before adding any
of the subitems.

With X
' add this so that style of the listitem is NOT
' used for all the subitems.
.UseItemStyleForSubItems = False
With .SubItems.Add(Rating)
.ForeColor = System.Drawing.Color.Red
End With
.SubItems.Add(Genre)
If OnLoan Then
.SubItems.Add("Yes")
Else
.SubItems.Add("No")
End If
.SubItems.Add(ToWho)
End With

Nov 21 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.