Results 1 to 5 of 5

Thread: ListView

  1. #1

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345
    Why does it not support a numeric key value?

    Actually I am trying to use a database field which has the data type as 'Text'. But its contents are all digits. This key is rejected by the ListView control.

    I know ListView doesn't support numeric keys. What is the workaround to this?

    Anyone who uses this control extensively in database applications, and has had similar problems?


    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I have only touched on listviews and I don't understand what you mean by Listview not supporting numeric keys.
    The code below sets up columns and you can add alpha, numeric, or date data

    'LOAD THE LISTVIEW WITH RANDOM INFORMATION
    'PUT THIS IN LOAD OR CLICK
    '
    Dim l As Long
    Dim dblRnd As Double
    Dim dteRnd As Date
    With ListView1
    ' Add three columns to the list - one for each data type.
    ' Note that the data type is set in the column header's
    ' tag in each case
    '
    .ColumnHeaders.Add(, , "String").Tag = "STRING"
    .ColumnHeaders.Add(, , "Number").Tag = "NUMBER"
    .ColumnHeaders.Add(, , "Date").Tag = "DATE"

    'you can sort a listview by number so it must handle numbers
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898
    just select a letter and concatenate the letter with the digits to make a key. If you need to refer back to the DB at anytime just strip the character first.

  4. #4
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186
    Yes! I know exactly what you mean. We have the same problem. The reason is because the creators of this control thought it would be very clever if the control could know inteligently when you are using a Key and when you are using an Index. Turns out it's not so clever after all.

    We get around it by adding a non-numeric character in front to force it to be a string, and later we use Mid$ to get the numeric value back:
    Code:
    Key = "_" & DataField
    Data = Mid$(Key , 2)
    Hope this helps.
    Shrog
    VB6 Ent SP5
    Win2000

  5. #5

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    HeSaidJoe, try this code:

    Place a listview control and a command button on a form and use the following:

    Code:
    Dim tmpItem As ListItem
    
    Private Sub Command1_Click()
    
       ListView1.ListItems.Clear
    
       Set tmpItem = ListView1.ListItems.Add(,"A102","A102")
       Set tmpItem = ListView1.ListItems.Add(,"102","102")
    
    End Sub
    You will be able to add the first listitem, and get an error on the second listitem.

    This error is because of the Key value used for the second listitem, which contains all numeric digits. This is the behaviour I am referring to.

    Bill Crawley and Shrogg, thanks for your replies. I am presently using the same work around, but I wanted to know if there is any better way. I guess there isn't.



    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

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