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

  • Thread starter Thread starter Guest
  • Start date Start date
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."
 
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
 
Back
Top