After searching i have found the following test codes to selecting multiple rows in a listbox :
Dim ids() As String
Dim sqL As String
Dim combined As String
for rowIndex as Integer = 0 to PurchasesList.ListCount - 1
ids.Append Str(PurchasesList.RowTag(rowIndex))
next
combined = Join(ids, ",")
sql = "DELETE FROM addressbook WHERE NRef IN" + combined
MsgBox(sql)
The problem is within combined variable, somehow in my part it’s always empty. Also in my database the rowid is starting with “1” instead of “0”.
How to approach my condition?, to selecting a/couple rows and delete/edit it in database?, from above code, deleting the database records seems easy enough but how to edit multiple records in the database at once? Need looping?.
I am also have put the code above in the event CellClick, is it “CellClick” the appropriate listbox event for multiple selecting row?
[code]Public Function ToString(extends anIntegerArray() as Integer, withBetweenChar as String = “,”) as String
dim i as integer
dim ch as string
dim lines() as String
ch=""
if UBound( anIntegerArray)>=0 then
for i=0 to UBound(anIntegerArray)
lines.Append str(anIntegerArray(i))
next
end if
Return Join( lines, withBetweenChar)
End Function
[/code]
then you can use
sql = "DELETE FROM addressbook WHERE NRef IN (" + ids.toString+")"
Thanks for all peoples who is replying, but coming from background of non-native english speaker, can someone explained the real/descriptive purposes of listbox.rowtag?
Tried @Jeff Tullin code but combined still empty :
ids :
RowTag is a place where you can put some information that will not be displayed on your listbox cells, like a secret box where you can put something and then your code can ask for it.
Sometimes with databases your primary key ID is a value that increase as each record is added and maybe is not used for other things. I have a database with primary key ID, Date and Currency, my listbox shows the Date and the Value but not the ID, I store the ID within RowTag to know what record to edit when I change the Currency.
If you don’t write anything to RowTag, then the RowTag will be empty.
If your database primary key ID is ProductID, then you don’t need RowTag and just use ProductID.