Click here to Skip to main content
14,733,542 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have DataGridView Control on form in vb.net on the 6th column. i connected it with connections string and datatable dt but when prog run and i click 1st time on combobox in column it shows proper list of database field but when i click on 2nd time row and click on combobox it shows the items repeatedly. why ? and how to remove this error

What I have tried:

i disconnected connection string but no use,
i used combobox1.items.removeAt(dt.rows.count) also not used
i changed the event of combobox & Grid but no use
Posted
Updated 5-Aug-20 2:09am
v2

1 solution

Without your code, It's pretty much impossible to be specific, but if every item is being duplicated, then you aren't emptying the collection your are displaying from before you add the new items.
If you are call Add or AddRange to add individual items to a DataGridView, then you need to Clear it before you do that.

A better solution is to collect the items from your DB in a DataTable (try a DataAdapter) and use that as the DataGridView.DataSource directly. You can then set the DisplayMember and ValueMember properties of the DataGridView to select which column(s) to use: combobox.DisplayMember property[^]
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900