A
Amr_Aly
Guest
Hi Everybody,
I used this snippet to load customer name to a text box
Sub autocomplete()
conn = New OleDbConnection(cs)
conn.Open()
Dim cmd As New OleDbCommand("SELECT B_name FROM Customer", conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "My List")
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("B_name").ToString())
Next
B_name.AutoCompleteSource = AutoCompleteSource.CustomSource
B_name.AutoCompleteCustomSource = col
B_name.AutoCompleteMode = AutoCompleteMode.Suggest
conn.Close()
End Sub
But when i used the same code for Address in the same form an error occurs called 'CallbackOnCollectedDelegate'
Sub autocompleteAddress()
Using conn = New OleDbConnection(cs)
conn.Open()
Using cmd As New OleDbCommand
cmd.Connection = conn
cmd.CommandText = "SELECT B_Address FROM Customer"
Using ds As New DataSet, da As New OleDbDataAdapter(cmd)
da.Fill(ds, "List")
Dim acsc As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
acsc.Add(ds.Tables(0).Rows(i)("B_Address").ToString())
Next
B_Address.AutoCompleteSource = AutoCompleteSource.CustomSource
B_Address.AutoCompleteCustomSource = acsc
B_Address.AutoCompleteMode = AutoCompleteMode.Suggest
End Using
End Using
End Using
End Sub
I used this snippets as follows
Private Sub Panel1_Enter(sender As Object, e As EventArgs) Handles Panel1.Enter
autocomplete()
End Sub
Private Sub B_name_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles B_name.Validating
autocompleteAddress()
End Sub
The full message says :
Additional information: A callback was made on a garbage collected delegate of type 'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
I searched here and i found a same problem with combo boxes ..... Only solution came to my mind that i delete one of the both subrotines , and change the text box of address to combo box , but i think there is another solution to this problem ......
Any suggestions ...
Thanks in advance ......
Regards From Amr_Aly
Continue reading...
I used this snippet to load customer name to a text box
Sub autocomplete()
conn = New OleDbConnection(cs)
conn.Open()
Dim cmd As New OleDbCommand("SELECT B_name FROM Customer", conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "My List")
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("B_name").ToString())
Next
B_name.AutoCompleteSource = AutoCompleteSource.CustomSource
B_name.AutoCompleteCustomSource = col
B_name.AutoCompleteMode = AutoCompleteMode.Suggest
conn.Close()
End Sub
But when i used the same code for Address in the same form an error occurs called 'CallbackOnCollectedDelegate'
Sub autocompleteAddress()
Using conn = New OleDbConnection(cs)
conn.Open()
Using cmd As New OleDbCommand
cmd.Connection = conn
cmd.CommandText = "SELECT B_Address FROM Customer"
Using ds As New DataSet, da As New OleDbDataAdapter(cmd)
da.Fill(ds, "List")
Dim acsc As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
acsc.Add(ds.Tables(0).Rows(i)("B_Address").ToString())
Next
B_Address.AutoCompleteSource = AutoCompleteSource.CustomSource
B_Address.AutoCompleteCustomSource = acsc
B_Address.AutoCompleteMode = AutoCompleteMode.Suggest
End Using
End Using
End Using
End Sub
I used this snippets as follows
Private Sub Panel1_Enter(sender As Object, e As EventArgs) Handles Panel1.Enter
autocomplete()
End Sub
Private Sub B_name_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles B_name.Validating
autocompleteAddress()
End Sub
The full message says :
Additional information: A callback was made on a garbage collected delegate of type 'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
I searched here and i found a same problem with combo boxes ..... Only solution came to my mind that i delete one of the both subrotines , and change the text box of address to combo box , but i think there is another solution to this problem ......
Any suggestions ...
Thanks in advance ......
Regards From Amr_Aly
Continue reading...