Datagridview keeps adding unwanted new column

sijcooke

Member
Joined
Nov 29, 2009
Messages
9
Programming Experience
10+
Hi all.... if anyone can help me with this i would be very greatfull! Im using VB08 Express Edition

I have simply made a new project (windows form application). Put 2 dataviewgrids on the form. Added 3 columns to each grid (at design time).

I then added one line of code as follows to the rows added event.

Private Sub DataGridView1_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded

DataGridView2.RowCount = DataGridView1.RowCount

End Sub


This works ie when you add a row to datagridview1, it also adds one to datagridview2 - BUT when the project first loads, it adds an extra column before my columns....

Why is this? is it a bug in vb.

Thanks for any help given, sijcooke!
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,316
Location
Norway
Programming Experience
10+
I can confirm the bug, I don't know why, but this is one way to resolve it:
Code:
If Me.DataGridView1.RowCount > 1 Then DataGridView2.RowCount = DataGridView1.RowCount
 
Top Bottom