How to assign a value in DataGridView.Rows?

jfecardona

Member
Joined
May 4, 2011
Messages
7
Location
Alegria Cebu, Philippines
Programming Experience
1-3
This is my situation, I created a class which inherits a DataGridView(XDGView), and another Class (XDGRowColl) which inherits a DataGridViewRowCollection. I Created XDGRowColl because I wanted to override its property which is remove, removeAt and Clear. Now what I wanted to do is to assign XDGRowColl to XDGView.Rows:

Public Sub New()
MyBase.Rows = New XDGRowColl
InitializeComponent()
End Sub

But 'MyBase.Rows = New XDGRowColl' says MyBase.Rows is a ReadOnly

Is there any other way to use XDGRowColl as my Default Row in XDGView?

Thanks in advance :)
 
Hi JohnH,

I tried overriding CreateRowInstance Method but it throws an error "No row can be added to a DataGridView control that does not have columns. Columns must be added first." This error comes after this line "XDataGrid1.Rows.Add(4)" I already added columns before this code and I wonder why it keeps on saying that there is no columns added.. What do you think is wrong with it? This is how i contruct my code in CreateRowInstance:

Protected Overrides Function CreateRowsInstance() As System.Windows.Forms.DataGridViewRowCollection
Return New XDGViewRowCollection
End Function

I put it in my XDGView class,

Thanks.. :D
 
If your XDGViewRowCollection constructor also adds rows to the collection then you are in effect adding rows to a grid that has no columns, thus that exception.
 
Back
Top