Results 1 to 11 of 11

Thread: [RESOLVED] Writing to ListView Problem

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] Writing to ListView Problem

    I am using VB6, ADO and Access 2002.

    I am trying to write the first three fields from a Db to a listview;
    Fields names are:
    First_Name, Middle_Name, Surname.

    Now the name may, or may not have a middle name, and I think this is what is causing me the problem

    I am getting something wrong with the writing to the Listview, but I'm not sure why.

    I am getting the error

    Invalid property value

    when the second item is to be added.

    My Code:
    vb Code:
    1. Set rs = New ADODB.Recordset
    2. Set cn = New ADODB.Connection
    3. cn.ConnectionString = strConnection & App.Path & "\Membership.mdb"
    4. cn.Open
    5.  
    6. strSQL = "SELECT First_Name, Middle_Name, Surname FROM tbl_Membership "
    7. strSQL = strSQL & " WHERE First_Name <> '""'"
    8. rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    9.  
    10. i = 1
    11.  
    12. Do While Not rs.EOF
    13.     If rs!Middle_Name <> "" Then
    14.         If i = 1 Then
    15.             Set lvwItem = lvwMembers.ListItems.Add(, , rs!First_Name & " " & rs!Middle_Name & " " & rs!Surname)
    16.         Else
    17.             lvwItem.SubItems(i) = rs!First_Name & " " & rs!Middle_Name & " " & rs!Surname
    18.         End If
    19.     Else
    20.         If i = 1 Then
    21.             Set lvwItem = lvwMembers.ListItems.Add(, , rs!First_Name & " " & rs!Surname)
    22.         Else
    23.             lvwItem.SubItems(i) = rs!First_Name & " " & rs!Surname
    24.         End If
    25.     End If
    26.    
    27.     i = i + 1
    28.     rs.MoveNext
    29. Loop
    30. Set rs = Nothing
    31. cn.Close
    32. Set cn = Nothing
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Writing to ListView Problem

    I'm not getting what you are doing?

    What is going on with the i variable? Why not just loop through the recordset and load what is there? If there is no middle name, nothing will be in the column.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Writing to ListView Problem

    Are you trying to add all three fields into one column?

  4. #4

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Writing to ListView Problem

    Quote Originally Posted by Hack
    Are you trying to add all three fields into one column?
    Yes, because I don't want a gap in the middle column if there is no middle name.

    I am trying to populate a listview with all members names from a database.
    Then, when the user selects one of the names, the complete record for this member is added into an array of textboxes.

    Also, I would like to have a second column (hidden) with the Primary key in it to know which record to show.

    Is this the best way to do this?
    Last edited by aikidokid; May 30th, 2007 at 12:53 PM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Writing to ListView Problem

    I would have three columns. One for the first name, one for the middle name, and one for the last name.

    Just click on the desired column, scoop all three up and run your query.

  6. #6

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Writing to ListView Problem

    Quote Originally Posted by Hack
    I would have three columns. One for the first name, one for the middle name, and one for the last name.

    Just click on the desired column, scoop all three up and run your query.
    So you wouldn't worry about there being an empty column then?
    Again, If I wanted to add a fourth column for the ID of the record, to make it hidden, is this done at runtime, or am I missing one of the properties?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Writing to ListView Problem

    If there is an empty column in your ListView it will be because there is an empty field in your database.

    You can add the column in design. Just set its width to 0

  8. #8

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Writing to ListView Problem

    Quote Originally Posted by Hack
    You can add the column in design. Just set its width to 0
    Just done this

    I'm just not sure what the proper standards are.
    This project is not just for me to use, so I want it to look right, and the way people expect it to look, if you know what I mean.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Writing to ListView Problem

    If you don't separate them, chances are you might have to parse the darn string just to get the names into three variables (I have no idea why, but it seems everytime I try to do something like this, that always happens.)

    Plus, I think it would look much better with three separate columns.

  10. #10

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Writing to ListView Problem

    Quote Originally Posted by Hack
    If you don't separate them, chances are you might have to parse the darn string just to get the names into three variables (I have no idea why, but it seems everytime I try to do something like this, that always happens.)
    Hmm, I was actually looking at this when you first replied to the thread :LOL:

    Quote Originally Posted by Hack
    Plus, I think it would look much better with three separate columns.
    This is the sort of thing you know, as a professional programmer, but I have to guess at. I'm never really happy with my designs, but I guess that comes in time
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Writing to ListView Problem

    Quote Originally Posted by aikidokid
    Hmm, I was actually looking at this when you first replied to the thread :LOL:
    Actually, with only three items it would be fairly easy to do using Split.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width