Will somebody tell me what I am doing wrong with this ListView Control 
Author Message
 Will somebody tell me what I am doing wrong with this ListView Control

My objective is to build a report based Listview showing all the customers
in my Customer Table

I want to uniquely identify each row of the collection with the primary key
from the customer table. So that i can reference that when a row is
selected.

My code, however, generates a runtime error:         35603 Invalid key.

Here is a description of the .Add method  from my MSDN library:
===================================================================
object.Add(index, key, text, icon, smallIcon)

The Add method syntax has these parts:

Part Description
object     Required. An object expression that evaluates to a ListItems
collection.
index     Optional. An integer specifying the position where you want to
insert the ListItem. If no index
                is specified, the ListItem is added to the end of the
ListItems collection.
key         Optional. A unique string expression that can be used to access
a member of the collection.

additionally:
string expression
Any expression that evaluates to a sequence of contiguous characters.
Elements of a string expression can include a function that returns a
string, a string literal, a string constant, a string variable, a string
Variant, or a function that returns a string Variant (VarType 8).
========================================================================

I am presenting the statement with what I believe to be a unique string. The
field rsCustomer!ID is a unique primary key and I am casting it as a string
expression

Here is the code:
=========================================================================
Private Sub Form_Load()
   Dim I As Integer
   Dim J As Integer

   cmdSelect.Enabled = False

   de1.cn1.Open
   de1.rsCustomer.Open , , adOpenStatic, adLockReadOnly

   With lv1
      .View = lvwReport
      .FullRowSelect = True

      For I = 1 To 8
         .ColumnHeaders.Add
         .ColumnHeaders(I).Text = de1.rsCustomer.Fields(I).Name

      Next I
   End With

   With de1.rsCustomer
      .MoveFirst
      I = 1
      Dim strTmp As String
      Do Until .EOF

        'Here is the problem line. I have tried Str(!ID), CStr(!ID), and
setting a string variable to !ID prior to
        'invoking the line as in strTmp = Str(!Id) ... lv1.ListItems.Add ,
strTmp
        ' As far as I am concerned, setting the value of index to I is
extraneous.
        'I can't use I to identify the record in the table

         lv1.ListItems.Add I, Str(!ID)

         lv1.ListItems(I).Text = .Fields(1).Value
         For J = 2 To 8
             lv1.ListItems(I).ListSubItems.Add
            lv1.ListItems(I).ListSubItems(J - 1).Text = .Fields(J).Value &
""
         Next J
         .MoveNext
         I = I + 1
      Loop
   End With
   lv1.Sorted = True
   Me.Show

End Sub
===============================================================



Thu, 25 Sep 2003 01:39:47 GMT  
 Will somebody tell me what I am doing wrong with this ListView Control
Henry,


Quote:
> My code, however, generates a runtime error:         35603 Invalid key.

Stick an "X" or some other letter on the front of your ID.

    -djm


Quote:
> My objective is to build a report based Listview showing all the customers
> in my Customer Table

> I want to uniquely identify each row of the collection with the primary
key
> from the customer table. So that i can reference that when a row is
> selected.

> My code, however, generates a runtime error:         35603 Invalid key.

> Here is a description of the .Add method  from my MSDN library:
> ===================================================================
> object.Add(index, key, text, icon, smallIcon)

> The Add method syntax has these parts:

> Part Description
> object     Required. An object expression that evaluates to a ListItems
> collection.
> index     Optional. An integer specifying the position where you want to
> insert the ListItem. If no index
>                 is specified, the ListItem is added to the end of the
> ListItems collection.
> key         Optional. A unique string expression that can be used to
access
> a member of the collection.

> additionally:
> string expression
> Any expression that evaluates to a sequence of contiguous characters.
> Elements of a string expression can include a function that returns a
> string, a string literal, a string constant, a string variable, a string
> Variant, or a function that returns a string Variant (VarType 8).
> ========================================================================

> I am presenting the statement with what I believe to be a unique string.
The
> field rsCustomer!ID is a unique primary key and I am casting it as a
string
> expression

> Here is the code:
> =========================================================================
> Private Sub Form_Load()
>    Dim I As Integer
>    Dim J As Integer

>    cmdSelect.Enabled = False

>    de1.cn1.Open
>    de1.rsCustomer.Open , , adOpenStatic, adLockReadOnly

>    With lv1
>       .View = lvwReport
>       .FullRowSelect = True

>       For I = 1 To 8
>          .ColumnHeaders.Add
>          .ColumnHeaders(I).Text = de1.rsCustomer.Fields(I).Name

>       Next I
>    End With

>    With de1.rsCustomer
>       .MoveFirst
>       I = 1
>       Dim strTmp As String
>       Do Until .EOF

>         'Here is the problem line. I have tried Str(!ID), CStr(!ID), and
> setting a string variable to !ID prior to
>         'invoking the line as in strTmp = Str(!Id) ... lv1.ListItems.Add ,
> strTmp
>         ' As far as I am concerned, setting the value of index to I is
> extraneous.
>         'I can't use I to identify the record in the table

>          lv1.ListItems.Add I, Str(!ID)

>          lv1.ListItems(I).Text = .Fields(1).Value
>          For J = 2 To 8
>              lv1.ListItems(I).ListSubItems.Add
>             lv1.ListItems(I).ListSubItems(J - 1).Text = .Fields(J).Value &
> ""
>          Next J
>          .MoveNext
>          I = I + 1
>       Loop
>    End With
>    lv1.Sorted = True
>    Me.Show

> End Sub
> ===============================================================



Thu, 25 Sep 2003 02:10:52 GMT  
 Will somebody tell me what I am doing wrong with this ListView Control
Listview keys can not be a purely numeric key (a stupid limitation), so
append some text to the end of the ID...

  cstr(ID) & "xxx"

 This allows you to use the Val function to rerieve the numeric value
without having to parse the string back out of the key.

  ID = Val (the key. ie 1234xxx)

--

Randy Birch
MVP Visual Basic

Take the vb.net poll at:
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please respond only to the newsgroups so all can benefit.


: My objective is to build a report based Listview showing all the customers
: in my Customer Table
:
: I want to uniquely identify each row of the collection with the primary
key
: from the customer table. So that i can reference that when a row is
: selected.
:
: My code, however, generates a runtime error:         35603 Invalid key.
:
: Here is a description of the .Add method  from my MSDN library:
: ===================================================================
: object.Add(index, key, text, icon, smallIcon)
:
: The Add method syntax has these parts:
:
: Part Description
: object     Required. An object expression that evaluates to a ListItems
: collection.
: index     Optional. An integer specifying the position where you want to
: insert the ListItem. If no index
:                 is specified, the ListItem is added to the end of the
: ListItems collection.
: key         Optional. A unique string expression that can be used to
access
: a member of the collection.
:
: additionally:
: string expression
: Any expression that evaluates to a sequence of contiguous characters.
: Elements of a string expression can include a function that returns a
: string, a string literal, a string constant, a string variable, a string
: Variant, or a function that returns a string Variant (VarType 8).
: ========================================================================
:
: I am presenting the statement with what I believe to be a unique string.
The
: field rsCustomer!ID is a unique primary key and I am casting it as a
string
: expression
:
: Here is the code:
: =========================================================================
: Private Sub Form_Load()
:    Dim I As Integer
:    Dim J As Integer
:
:    cmdSelect.Enabled = False
:
:    de1.cn1.Open
:    de1.rsCustomer.Open , , adOpenStatic, adLockReadOnly
:
:    With lv1
:       .View = lvwReport
:       .FullRowSelect = True
:
:       For I = 1 To 8
:          .ColumnHeaders.Add
:          .ColumnHeaders(I).Text = de1.rsCustomer.Fields(I).Name
:
:       Next I
:    End With
:
:    With de1.rsCustomer
:       .MoveFirst
:       I = 1
:       Dim strTmp As String
:       Do Until .EOF
:
:         'Here is the problem line. I have tried Str(!ID), CStr(!ID), and
: setting a string variable to !ID prior to
:         'invoking the line as in strTmp = Str(!Id) ... lv1.ListItems.Add ,
: strTmp
:         ' As far as I am concerned, setting the value of index to I is
: extraneous.
:         'I can't use I to identify the record in the table
:
:          lv1.ListItems.Add I, Str(!ID)
:
:          lv1.ListItems(I).Text = .Fields(1).Value
:          For J = 2 To 8
:              lv1.ListItems(I).ListSubItems.Add
:             lv1.ListItems(I).ListSubItems(J - 1).Text = .Fields(J).Value &
: ""
:          Next J
:          .MoveNext
:          I = I + 1
:       Loop
:    End With
:    lv1.Sorted = True
:    Me.Show
:
: End Sub
: ===============================================================
:
:



Thu, 25 Sep 2003 02:32:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Please tell me what I am doing wrong - DAO parameter Append Query :(

2. What am I doing wrong (listview)

3. What am I doing wrong (listview)

4. What am I doing wrong (listview)

5. What am I doing wrong (listview)

6. What am I doing wrong (listview)

7. What am I doing wrong (listview)

8. What am I doing wrong (listview)

9. ADO Data Control - What Am I Doing Wrong?

10. Referring to controls - What am I doing wrong???

11. Referring to controls - What am I doing wrong???

12. tell another program i am done

 

 
Powered by phpBB® Forum Software