Home All Groups Group Topic Archive Search About

error when updating Listview after record add

Author
17 May 2009 7:49 PM
Co
Hi All,

I have a Listview that shows some records from a database.
When I click on one of the files in the Listview the details are shown
in a subwindow on my form.
Now when I add a new record by DragDrop on the Listview the view gets
updated so the newly added
file is shown.
In the subwindow I can then edit the details of the record. But when I
edit a newly added record and click
save I get an error message:

InvalidArgument = Value of '6' is not valid for 'index'.

The next code saves the details of the record in the Subwindow:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

        Dim sql As String = "SELECT * FROM Bestanden WHERE Id=" &
IDclicked
        Dim da As New OleDb.OleDbDataAdapter(sql, conn)
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim ds As New DataSet
        conn.Open()
        Try
            da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
            da.Fill(ds)
            If ds.Tables.Count > 0 _
            AndAlso ds.Tables(0).Rows.Count > 0 Then
                Dim dr As DataRow = ds.Tables(0).Rows(0)
                dr.Item("kenmerk") = tbKenmerk.Text
                dr.Item("status") = tbStatus.Text
                dr.Item("auteur") = tbAuteur.Text
                dr.Item("datum_gewijzigd") = tbGewijzigd.Text
                dr.Item("expires") = tbVerloopt.Text
                dr.Item("hddlokatie") = tbFysiekeLokatie.Text
                dr.Item("samenvatting") = tbSamenvatting.Text
                dr.Item("soort") = tbSoort.Text
                dr.Item("rubricering") = tbRubricering.Text
                dr.Item("inuit") = tbInUit.Text

                'sent the updated dataSet to the database
                da.Update(ds)
                UpdateListViewNode(IDclicked, dr)
            End If
        Catch oException As OleDbException
            MessageBox.Show(oException.Message)

        Catch oException As Exception
            MessageBox.Show(oException.Message)

        End Try
        conn.Close()
        EnableAllFields(False)
        btnSave.Visible = False
        btnCancel.Visible = False
        btnExploreFysiekeLokatie.Visible = False
        tbSamenvatting.ForeColor = Color.Gray
        tbVerloopt.ReadOnly = True
    End Sub

The next code updates the Listview and raises the error message:

Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
DataRow)

        Dim Key As String = CStr(ID)
        If ListView.Items.ContainsKey(Key) Then
            Dim lvItem As ListViewItem = ListView.Items(Key)
            lvItem.Text = CStr(Dr.Item("filenaam"))
            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
            lvItem.SubItems(5).Text = FixNull(Dr.Item
("datum_gewijzigd"))
            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
        End If

    End Sub

Can anyone tell me why this error occures?

Regards
Marco
The Netherlands (Not SA).

Author
17 May 2009 8:19 PM
Cor Ligthert[MVP]
Co,

The answer is simple, use a DataGridView and remove the vertical header
column and set some more properties to by instance remove the add row
button, than you have a better listview, which you simply can use with a
datasource for your datatable.

Cor

Show quoteHide quote
"Co" <vonclausow***@gmail.com> wrote in message
news:674a145e-70a5-4e2e-96b6-4133497fda28@s28g2000vbp.googlegroups.com...
> Hi All,
>
> I have a Listview that shows some records from a database.
> When I click on one of the files in the Listview the details are shown
> in a subwindow on my form.
> Now when I add a new record by DragDrop on the Listview the view gets
> updated so the newly added
> file is shown.
> In the subwindow I can then edit the details of the record. But when I
> edit a newly added record and click
> save I get an error message:
>
> InvalidArgument = Value of '6' is not valid for 'index'.
>
> The next code saves the details of the record in the Subwindow:
>
> Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnSave.Click
>
>        Dim sql As String = "SELECT * FROM Bestanden WHERE Id=" &
> IDclicked
>        Dim da As New OleDb.OleDbDataAdapter(sql, conn)
>        Dim cb As New OleDb.OleDbCommandBuilder(da)
>        Dim ds As New DataSet
>        conn.Open()
>        Try
>            da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
>            da.Fill(ds)
>            If ds.Tables.Count > 0 _
>            AndAlso ds.Tables(0).Rows.Count > 0 Then
>                Dim dr As DataRow = ds.Tables(0).Rows(0)
>                dr.Item("kenmerk") = tbKenmerk.Text
>                dr.Item("status") = tbStatus.Text
>                dr.Item("auteur") = tbAuteur.Text
>                dr.Item("datum_gewijzigd") = tbGewijzigd.Text
>                dr.Item("expires") = tbVerloopt.Text
>                dr.Item("hddlokatie") = tbFysiekeLokatie.Text
>                dr.Item("samenvatting") = tbSamenvatting.Text
>                dr.Item("soort") = tbSoort.Text
>                dr.Item("rubricering") = tbRubricering.Text
>                dr.Item("inuit") = tbInUit.Text
>
>                'sent the updated dataSet to the database
>                da.Update(ds)
>                UpdateListViewNode(IDclicked, dr)
>            End If
>        Catch oException As OleDbException
>            MessageBox.Show(oException.Message)
>
>        Catch oException As Exception
>            MessageBox.Show(oException.Message)
>
>        End Try
>        conn.Close()
>        EnableAllFields(False)
>        btnSave.Visible = False
>        btnCancel.Visible = False
>        btnExploreFysiekeLokatie.Visible = False
>        tbSamenvatting.ForeColor = Color.Gray
>        tbVerloopt.ReadOnly = True
>    End Sub
>
> The next code updates the Listview and raises the error message:
>
> Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
> DataRow)
>
>        Dim Key As String = CStr(ID)
>        If ListView.Items.ContainsKey(Key) Then
>            Dim lvItem As ListViewItem = ListView.Items(Key)
>            lvItem.Text = CStr(Dr.Item("filenaam"))
>            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
>            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
>            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
>            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
>            lvItem.SubItems(5).Text = FixNull(Dr.Item
> ("datum_gewijzigd"))
>            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
>            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
>            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
>        End If
>
>    End Sub
>
> Can anyone tell me why this error occures?
>
> Regards
> Marco
> The Netherlands (Not SA).
Author
17 May 2009 8:30 PM
Co
Show quote Hide quote
On 17 mei, 22:19, "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl>
wrote:
> Co,
>
> The answer is simple, use a DataGridView and remove the vertical header
> column and set some more properties to by instance remove the add row
> button, than you have a better listview, which you simply can use with a
> datasource for your datatable.
>
> Cor
>
> "Co" <vonclausow***@gmail.com> wrote in message
>
> news:674a145e-70a5-4e2e-96b6-4133497fda28@s28g2000vbp.googlegroups.com...
>
> > Hi All,
>
> > I have a Listview that shows some records from a database.
> > When I click on one of the files in the Listview the details are shown
> > in a subwindow on my form.
> > Now when I add a new record by DragDrop on the Listview the view gets
> > updated so the newly added
> > file is shown.
> > In the subwindow I can then edit the details of the record. But when I
> > edit a newly added record and click
> > save I get an error message:
>
> > InvalidArgument = Value of '6' is not valid for 'index'.
>
> > The next code saves the details of the record in the Subwindow:
>
> > Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles btnSave.Click
>
> >        Dim sql As String = "SELECT * FROM Bestanden WHERE Id=" &
> > IDclicked
> >        Dim da As New OleDb.OleDbDataAdapter(sql, conn)
> >        Dim cb As New OleDb.OleDbCommandBuilder(da)
> >        Dim ds As New DataSet
> >        conn.Open()
> >        Try
> >            da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
> >            da.Fill(ds)
> >            If ds.Tables.Count > 0 _
> >            AndAlso ds.Tables(0).Rows.Count > 0 Then
> >                Dim dr As DataRow = ds.Tables(0).Rows(0)
> >                dr.Item("kenmerk") = tbKenmerk.Text
> >                dr.Item("status") = tbStatus.Text
> >                dr.Item("auteur") = tbAuteur.Text
> >                dr.Item("datum_gewijzigd") = tbGewijzigd.Text
> >                dr.Item("expires") = tbVerloopt.Text
> >                dr.Item("hddlokatie") = tbFysiekeLokatie.Text
> >                dr.Item("samenvatting") = tbSamenvatting.Text
> >                dr.Item("soort") = tbSoort.Text
> >                dr.Item("rubricering") = tbRubricering..Text
> >                dr.Item("inuit") = tbInUit.Text
>
> >                'sent the updated dataSet to the database
> >                da.Update(ds)
> >                UpdateListViewNode(IDclicked, dr)
> >            End If
> >        Catch oException As OleDbException
> >            MessageBox.Show(oException.Message)
>
> >        Catch oException As Exception
> >            MessageBox.Show(oException.Message)
>
> >        End Try
> >        conn.Close()
> >        EnableAllFields(False)
> >        btnSave.Visible = False
> >        btnCancel.Visible = False
> >        btnExploreFysiekeLokatie.Visible = False
> >        tbSamenvatting.ForeColor = Color.Gray
> >        tbVerloopt.ReadOnly = True
> >    End Sub
>
> > The next code updates the Listview and raises the error message:
>
> > Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
> > DataRow)
>
> >        Dim Key As String = CStr(ID)
> >        If ListView.Items.ContainsKey(Key) Then
> >            Dim lvItem As ListViewItem = ListView.Items(Key)
> >            lvItem.Text = CStr(Dr.Item("filenaam"))
> >            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
> >            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
> >            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
> >            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
> >            lvItem.SubItems(5).Text = FixNull(Dr.Item
> > ("datum_gewijzigd"))
> >            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
> >            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
> >            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
> >        End If
>
> >    End Sub
>
> > Can anyone tell me why this error occures?
>
> > Regards
> > Marco
> > The Netherlands (Not SA).

Thanks for the advice Cor but I use a Listview.

MArco
Author
18 May 2009 10:03 AM
Andrew Morton
Co wrote:

> In the subwindow I can then edit the details of the record. But when I
> edit a newly added record and click
> save I get an error message:
>
> InvalidArgument = Value of '6' is not valid for 'index'.
>
> Can anyone tell me why this error occures?

It would help if you said exactly which line generates the error.

If you edit an item that isn't at the end of the list of records, does it
update the wrong one, indicating an off-by-one error?

Andrew
Author
18 May 2009 12:44 PM
Co
Show quote Hide quote
On 18 mei, 12:03, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote:
> Co wrote:
> > In the subwindow I can then edit the details of the record. But when I
> > edit a newly added record and click
> > save I get an error message:
>
> > InvalidArgument = Value of '6' is not valid for 'index'.
>
> > Can anyone tell me why this error occures?
>
> It would help if you said exactly which line generates the error.
>
> If you edit an item that isn't at the end of the list of records, does it
> update the wrong one, indicating an off-by-one error?
>
> Andrew

Andres,

It does update the right record but I think it has something to do
with loading the Listview.

This code produces the error:

Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
DataRow)


        Dim Key As String = CStr(ID)
        If ListView.Items.ContainsKey(Key) Then
            Dim lvItem As ListViewItem = ListView.Items(Key)
            lvItem.Text = CStr(Dr.Item("filenaam"))
            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
            lvItem.SubItems(5).Text = FixNull(Dr.Item
("datum_gewijzigd"))
            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
        End If


    End Sub

Not sure which line but I think it has to do with the SubItems.
Wild guess...

Marco
Author
18 May 2009 1:04 PM
Andrew Morton
Co wrote:
> On 18 mei, 12:03, "Andrew Morton" wrote:
>> Co wrote:
>>> In the subwindow I can then edit the details of the record. But
>>> when I edit a newly added record and click
>>> save I get an error message:
>>
>>> InvalidArgument = Value of '6' is not valid for 'index'.
>>
>>> Can anyone tell me why this error occures?
>>
>> It would help if you said exactly which line generates the error.
>
> This code produces the error:
>
<snip>

> Not sure which line but I think it has to do with the SubItems.
> Wild guess...

Wild guesses will not help. Have you tried using the debugger? Then you can
see exactly where the error comes from and, if it were relevant, examine
things like lvItem to see if it has the subitems you think it has.

Andrew
Author
18 May 2009 2:02 PM
Co
Show quote Hide quote
On 18 mei, 15:04, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote:
> Co wrote:
> > On 18 mei, 12:03, "Andrew Morton" wrote:
> >> Co wrote:
> >>> In the subwindow I can then edit the details of the record. But
> >>> when I edit a newly added record and click
> >>> save I get an error message:
>
> >>> InvalidArgument = Value of '6' is not valid for 'index'.
>
> >>> Can anyone tell me why this error occures?
>
> >> It would help if you said exactly which line generates the error.
>
> > This code produces the error:
>
> <snip>
>
> > Not sure which line but I think it has to do with the SubItems.
> > Wild guess...
>
> Wild guesses will not help. Have you tried using the debugger? Then you can
> see exactly where the error comes from and, if it were relevant, examine
> things like lvItem to see if it has the subitems you think it has.
>
> Andrew

Andrew,

I tested the code with the debugger and found the following.
First the Listview gets loaded through this code:

Public Sub LoadListView(ByVal tblID As Integer)
        ' Add items to the listview based on the selected item in the
treeview

        Dim lvItem As ListViewItem
        ListView.Items.Clear()
        Dim sql As String = "SELECT * FROM Bestanden WHERE lokatie=" &
tblID
        Dim cmd As New OleDbCommand(sql, conn)
        Dim dr As OleDbDataReader
        conn.Open()
        dr = cmd.ExecuteReader()

        Do While (dr.Read())
            Dim Key As String = CStr(dr.Item("Id"))
            Dim ImgIndex As Integer = CInt(dr.Item("extensie"))
            lvItem = ListView.Items.Add(Key, CStr(dr.Item
("filenaam")), ImgIndex)
            lvItem.Tag = dr.Item("Id")
            lvItem.SubItems.AddRange(New String() { _
              FixNull(dr.Item("kenmerk")), _
              CStr(dr.Item("grootte")), _
              CStr(dr.Item("auteur")), _
              CStr(dr.Item("datum_gemaakt")), _
              FixNull(dr.Item("datum_gewijzigd")), _
              FixNull(dr.Item("status")), _
              FixNull(dr.Item("soort")), _
              FixNull(dr.Item("inuit"))})
        Loop
        ListView.AutoResizeColumns
(ColumnHeaderAutoResizeStyle.HeaderSize)
        dr.Close()
        conn.Close()
        EmptyAllFields()
    End Sub

Then I add a new record and immediately click Edit. I save the record
and then get the error I mentioned, here:

Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
DataRow)

        Dim Key As String = CStr(ID)
        If ListView.Items.ContainsKey(Key) Then
            Dim lvItem As ListViewItem = ListView.Items(Key)
            lvItem.Text = CStr(Dr.Item("filenaam"))
            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
            lvItem.SubItems(5).Text = FixNull(Dr.Item
("datum_gewijzigd"))
            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
-------> This line the error occures!!!!
            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
        End If

    End Sub

Regards
Marco
Author
18 May 2009 3:07 PM
Andrew Morton
Co wrote:
Show quoteHide quote
>        Dim Key As String = CStr(ID)
>        If ListView.Items.ContainsKey(Key) Then
>            Dim lvItem As ListViewItem = ListView.Items(Key)
>            lvItem.Text = CStr(Dr.Item("filenaam"))
>            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
>            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
>            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
>            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
>            lvItem.SubItems(5).Text = FixNull(Dr.Item
> ("datum_gewijzigd"))
>            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
>            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
> -------> This line the error occures!!!!
>            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
>        End If

The SubItems probably start with an index of 0, not 1, i.e. they go from 0
to 7, not 1 to 8.

Andrew
Author
18 May 2009 4:26 PM
Co
Show quote Hide quote
On 18 mei, 17:07, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote:
> Co wrote:
> >        Dim Key As String = CStr(ID)
> >        If ListView.Items.ContainsKey(Key) Then
> >            Dim lvItem As ListViewItem = ListView.Items(Key)
> >            lvItem.Text = CStr(Dr.Item("filenaam"))
> >            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
> >            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
> >            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
> >            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
> >            lvItem.SubItems(5).Text = FixNull(Dr.Item
> > ("datum_gewijzigd"))
> >            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
> >            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
> > -------> This line the error occures!!!!
> >            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
> >        End If
>
> The SubItems probably start with an index of 0, not 1, i.e. they go from 0
> to 7, not 1 to 8.
>
> Andrew

Andrew,

Tried it but the error stays and the text get stored in the wrong
field of the Listview, so it ain't that.

MArco
Author
18 May 2009 5:19 PM
Co
On 18 mei, 18:26, Co <vonclausow***@gmail.com> wrote:
Show quoteHide quote
> On 18 mei, 17:07, "Andrew Morton" <a***@in-press.co.uk.invalid> wrote:
>
>
>
> > Co wrote:
> > >        Dim Key As String = CStr(ID)
> > >        If ListView.Items.ContainsKey(Key) Then
> > >            Dim lvItem As ListViewItem = ListView.Items(Key)
> > >            lvItem.Text = CStr(Dr.Item("filenaam"))
> > >            lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
> > >            lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
> > >            lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
> > >            lvItem.SubItems(4).Text = CStr(Dr.Item("datum_gemaakt"))
> > >            lvItem.SubItems(5).Text = FixNull(Dr.Item
> > > ("datum_gewijzigd"))
> > >            lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
> > >            lvItem.SubItems(7).Text = FixNull(Dr.Item("soort"))
> > > -------> This line the error occures!!!!
> > >            lvItem.SubItems(8).Text = FixNull(Dr.Item("inuit"))
> > >        End If
>
> > The SubItems probably start with an index of 0, not 1, i.e. they go from 0
> > to 7, not 1 to 8.
>
> > Andrew
>
> Andrew,
>
> Tried it but the error stays and the text get stored in the wrong
> field of the Listview, so it ain't that.
>
> MArco

I tried following code but the error stays the same:

Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
DataRow)

        Dim Key As String = CStr(ID)
        If ListView.Items.ContainsKey(Key) Then
            Dim lvItem As ListViewItem = ListView.Items(Key)
            lvItem.Text = CStr(Dr.Item("filenaam"))
            If lvItem.SubItems.Count > 0 Then
                lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
                lvItem.SubItems(2).Text = CStr(Dr.Item("grootte"))
                lvItem.SubItems(3).Text = CStr(Dr.Item("auteur"))
                lvItem.SubItems(4).Text = CStr(Dr.Item
("datum_gemaakt"))
                lvItem.SubItems(5).Text = FixNull(Dr.Item
("datum_gewijzigd"))
                lvItem.SubItems(6).Text = FixNull(Dr.Item("status"))
                If lvItem.SubItems(7).Text <> "" Then
                    lvItem.SubItems(7).Text = FixNull(Dr.Item
("soort"))
                End If
                If lvItem.SubItems(8).Text <> "" Then
                    lvItem.SubItems(8).Text = FixNull(Dr.Item
("inuit"))
                End If
            End If
        End If
    End Sub

The SubItems.Count value  = 7 when I run it.

MArco
Author
19 May 2009 7:43 AM
Andrew Morton
Co wrote:
> I tried following code but the error stays the same:
>
> Private Sub UpdateListViewNode(ByVal ID As Integer, ByVal Dr As
> DataRow)
>
>         Dim Key As String = CStr(ID)
>         If ListView.Items.ContainsKey(Key) Then
>             Dim lvItem As ListViewItem = ListView.Items(Key)
>             lvItem.Text = CStr(Dr.Item("filenaam"))
>             If lvItem.SubItems.Count > 0 Then
>                 lvItem.SubItems(1).Text = FixNull(Dr.Item("kenmerk"))
<snip>
>
> The SubItems.Count value  = 7 when I run it.
>

That tells you that the subitems go from 0 to 6, i.e. there are 7 of them.

Whereever you've added the subitems to it, you apparently haven't added all
the ones you intended.

Andrew