Removing an item from a listview 
Author Message
 Removing an item from a listview

Hi,

I get this error msg "Object Referenece not set to an instance of an
object", when I try to remove an object from my listbox.

What is the correct way to remove an item

Thanks

Dim obj As New clsObject

'

obj = DirectCast(lstOwners.SelectedItem, clsObject)

Dim sqlcmd As String

sqlcmd = "delete from tbl_propertyowner where property_id = " & intProperty
& " and contact_id ='" & obj.ID & "'"

Dim ordersCMDa As SqlCommand = New SqlCommand(sqlcmd, SqlConnection)

ordersCMDa.ExecuteScalar()

lstOwners.Items.Remove(lstOwners.SelectedItem)    ' <---- Error occurs at
this line



Fri, 09 Dec 2005 09:38:45 GMT  
 Removing an item from a listview
Hello,

Try changing the failed line of code as follows;

lstOwners.Items.Remove(lstOwners.SelectedItems(0))

Good luck


Quote:
> Hi,

> I get this error msg "Object Referenece not set to an instance of an
> object", when I try to remove an object from my listbox.

> What is the correct way to remove an item

> Thanks

> Dim obj As New clsObject

> '

> obj = DirectCast(lstOwners.SelectedItem, clsObject)

> Dim sqlcmd As String

> sqlcmd = "delete from tbl_propertyowner where property_id = " &
intProperty
> & " and contact_id ='" & obj.ID & "'"

> Dim ordersCMDa As SqlCommand = New SqlCommand(sqlcmd, SqlConnection)

> ordersCMDa.ExecuteScalar()

> lstOwners.Items.Remove(lstOwners.SelectedItem)    ' <---- Error occurs at
> this line



Sat, 10 Dec 2005 01:11:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Removing an item from a ListView

2. Remove selected items from a listview control in report format

3. ListView Control - Removing selected items from the list

4. help adding and removing items from a listview

5. Q: How to get rid of ListView flicker when adding/removing items

6. SHFileOp and removing corresponding items from ListView

7. removing items from a listview

8. Remove Selected item in ListView Control

9. ListView items remain indented after removing icons

10. How to remove items in a listview?

11. ListView: Remove items *AND* rows???

12. Removing items from ListView en masse

 

 
Powered by phpBB® Forum Software