I have combobox on child form. combobox get populated when form is loaded.

Now the problem is when child form is closed and reloaded combobox get populed twice with same items. it appears that combobox dosen get cleared when for is closed.

Below code dosen work

Below code is for closing form.

please suggest how to cleare combobox

Recommended Answers

All 7 Replies

cboScrip.Items.Clear() is the correct call to clear all items. I suggest you put the Clear just above the code that populates the combobox.

here is my code
Private Sub FrmTransection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Rno As Integer = 0
Call CnScrip()
Do While Rno <> MyDataTable.Rows.Count - 1
Rno = Rno + 1
End Sub

And does it still get duplicate items? If so, I suggest you add a


inside the loop just above the Add to see if the problem is with your DataTable.

i think there is problem with my datatable, but cannot find what it is?

Module MduConnection

Public MyConnection As New OleDb.OleDbConnection
Public MyAdapter As OleDb.OleDbDataAdapter
Public MyCmdBuilder As OleDb.OleDbCommandBuilder
Public MyDataTable As New DataTable
Public RowNo As Integer = 0

Public Sub CnScrip()
MyConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=D:\VB NET\DBMARKET\Market.accdb"
MyAdapter = New OleDb.OleDbDataAdapter("select*from Script", MyConnection)
MyCmdBuilder = New OleDb.OleDbCommandBuilder(MyAdapter)
End Sub

End Module

What was the output from the Debug.WriteLine I suggested?

You are not clearing MyDataTable before filling in CnScrip.
Try adding MyDataTable.Clear before MyAdapter.Fill(MyDataTable).


Its ok now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.