PROBLEM:"Cannot modify the Items collection when the DataSource...

G

Guest

Hello
I have a listbox with a datasource.I want to remove a row from listbox but
not remove it from the database.
How can i do this ?

PROBLEM:"Cannot modify the Items collection when the DataSource property is
set."
 
G

Guest

Hi VictorJOL,

I use the next code to connect with the database and load the listbox
control with the data of this db. (I connect, bind the data and disconnect)

Dim strConexion As String
Dim objConexion As OleDbConnection
Dim objComando As OleDbDataAdapter
Dim objDS As New DataSet
strConexion = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;" & "DATA SOURCE=" &
"C:\Ejemplo.mdb"
objConexion = New OleDbConnection(strConexion)
objComando = New OleDbDataAdapter("Select * From Tabla", strConexion)
objComando.Fill(objDS, "Ejemplo")
Dim Row
Dim Fila As DataRow
'intContador = 1
ListBox1.Items.Clear()
For Each Row In objDS.Tables("Ejemplo").Rows
ListBox1.Items.Add(Row(0))
Next
objConexion.Close()


Later, I remove an element of the listbox control, but the connection with
the db, is switch off.

ListBox1.Items.RemoveAt(2)

I hope that helps.

Kind Regards,

Jorge Serrano Pérez
MVP VB.NET
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top