Class Inherits DataGridView, Errors: Rows(0).DataGridView

Class Inherits DataGridView, Errors: Rows(0).DataGridView

Post by Niel » Fri, 05 Jan 2007 18:16:50


Hi,
When doing Class Inherits DataGridView, the Rows do not contain the a valid
owning Grid in the Rows(0).DataGridView member
Am I doing something wrong or, is there an easy fix? Ofcourse I can pass
MyGrid1 to ProcessRow as parameter. But I thought this should work?

Example

Public Class MyGrid
Inherits DataGridView
Public MyInteger as Integer
End Class

Dim MyGrid1 as MyGrid

ProcessRow(MyGrid1.Rows(0))

Sub ProcessRow(Row as DataGridViewRow)
Debug.Print Row.DataGridView.Name
'Error Row.DataGridView is Nothing
End Sub
 
 
 

1. DataGridView (.NET 2.0 Windows Forms) Text wrapping in DataGridView Items

2. Refreshing Linq query to update second DataGridView when position in first DataGridView changes

This seems to be something so simple that none of the hundred-odd tutorials
and forum threads that I have looked at (:-)) apparently thinks it's a
problem.

In a nutshell, I have two DataGridViews. Each has a BindingSource (and a
BindingNavigator). The first view populates successfully based upon a Linq
to SQL query in the Form Load (that is, the query is assigned to the
DataSource of that view's BindingSource, and the BindingSource is assigned
to the DataSource of the view). Or:

var personsQuery = from p in pim.persons
select p;

personBindingSource.DataSource = personsQuery;
personDataGridView.DataSource = personBindingSource;

The second view (which is actually address data accessed through a
person_address join table) is set up like:

addressBindingSource.DataSource = personsQuery;
addressDataGridView.DataSource = addressBindingSource;
addressDataGridView.DataMember = "addresses";

The method "addresses" in class "person" handles the join table. In any
case, when I run the app, the second DataGridView successfully populates
with the rows of the address table that correspond to the first row (first
"person") in the first DataGridView. So far so good.

Problem being, if I select another row in the first DataGridView (in this
example, a different "person"), I'd like to see the address or addresses
corresponding to that selected person. I have a SelectionChanged event
handler set up on the personDataGridView, and it is successfully reporting
the Position changes in the personBindingSource. I'll be damned if I can
figure out how to get the addressBindingSource to update, that is, to
effectively re-run the person.addresses method for a different person.

Any suggestions?

AHS

3. Binding List<T> to a DataGridView = DataGridView Empty

4. Copy from datagridview and paste to second datagridview

5. Clearing selection in DataGridView when user clicks outside the DataGridView control

6. DataGridView into another DataGridView

7. Adjusting DataGridView row heights on existing rows

8. Row highlight after deleting row in datagridview

9. Making DataGridView do row-by-row edit instead of cell-by-cell

10. Copy current row values to new row in DataGridView

11. Forcing DataGridView to repaint a row/disabling a row

12. DataGridView paste to (edit row), * row

13. DataGridView with rows in plus rows

14. Forcing DataGridView to repaint a row/disabling a row

15. DataGridView paste to (edit row), * row