i have listview , button
below code have used deletion of data listview
private sub btndelete_click(byval sender system.object, byval e system.eventargs) handles btndelete.click if lvnoteslist.selecteditems.count > 0 dim result = msgbox("are sure want delete selected item ?", messageboxbuttons.yesno + vbquestion) if result = dialogresult.yes dim id string = lvnoteslist.selecteditems(0).subitems(0).text try dim sqlconnection new sqlite.sqliteconnection() dim sqlcommand new sqlitecommand("", sqlconnection) dim sqlpath string = "data source=" & application.startuppath & "\database\simpledb.db3" dim sqlquery string = "delete notes noteid = " & id sqlconnection.connectionstring = sqlpath sqlconnection.open() sqlcommand.commandtext = sqlquery sqlcommand.executenonquery() sqlconnection.close() msgbox("operation successfull", vbinformation) catch ex exception msgbox("error: operation unsuccessfull." & chr(13) & "sumamry:" & ex.message, vbexclamation) end try else exit sub end if else msgbox("select item first", vbexclamation) end if end sub
for reason produces error this
how can fix ?
the msgbox
causes listview lose focus in turn clears selection. you'll have set hideselection
property of listview false
.
edit:
try this
if lvnoteslist.selecteditems.count > 0 dim id string = lvnoteslist.selecteditems(0).subitems(0).text dim result = msgbox("are sure want delete selected item ?", messageboxbuttons.yesno + vbquestion) if result = dialogresult.yes
Comments
Post a Comment