VB.net DataGridView  more additional columns than expected being added in

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. I am using the following code to populate a bound DataGridView and then add in an additional CheckBox column but for some reason 3 extra CheckBox columns are being added. Thanks      

          Dim connection As New OleDbConnection(ConnectionString)
                Dim dataadapter As New OleDbDataAdapter(sSQL, connection)
                Dim ds As New DataSet()
                connection.Open()
                dataadapter.Fill(ds, "Outstanding_table")
                connection.Close()
                DataGridView_Unpaid_Invoices.DataSource = ds
                DataGridView_Unpaid_Invoices.DataMember = "Outstanding_table"

            Me.DataGridView_Unpaid_Invoices.Columns.Insert(0, New DataGridViewCheckBoxColumn)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
the code you are using has no faults, anyway use this property to avoid adding more columns
 DataGridView1.AutoGenerateColumns = false
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Hi. Thanks for the code but nothing seems to change with your code
Commented:
dude, your code has no problem, are you sure everything is ok? I ran this piece of code and with no issues. Check if there is other things affecting like in some cases if the dataTable (Outstanding_table) contains a column of datatype (boolean) then it will be translated to checkbox within the datagridview.
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Right on! I  was calling the code from more than one event. Clearing the extra column at the beginning did the trick! Thanks for confirming that it works

Commented:
ur welcome dude.. glad it worked

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial