-
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 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
-
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.
-
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
-
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.
.