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
CboScrip.Items.Clear()

Below code is for closing form.
Me.Close()
Me.Dispose()

please suggest how to cleare combobox

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()
CboScrip.Items.Clear()
Do While Rno <> MyDataTable.Rows.Count - 1
Rno = Rno + 1
CboScrip.Items.Add(MyDataTable.Rows(Rno)("Script_Name"))
Loop
MyConnection.Close()
MyConnection.Dispose()
End Sub

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

Debug.WriteLine(MyDataTable.Rows(Rno)("Script_Name"))

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"
MyConnection.Open()
MyAdapter = New OleDb.OleDbDataAdapter("select*from Script", MyConnection)
MyCmdBuilder = New OleDb.OleDbCommandBuilder(MyAdapter)
MyAdapter.Fill(MyDataTable)
End Sub

End Module

Edited 4 Years Ago by PM312

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

This question has already been answered. Start a new discussion instead.