Bind/sync DataGridView.Rows with List

2 weeks ago 17
ARTICLE AD BOX

I have created a class inheriting the DataGridViewRow class. We'll call it CustomRowClass.

I have custom rows stored in a List<CustomRowClass> customRows.

Is there a way to bind a DataGridView's Rows collection to this list, so that any time there is a change to the list, like reordering or adding/removing items, that the DGV visually updates too automatically?

I know I could do

datagridview1.Rows.Clear(); datagridview1.Rows.AddRange(customRows);

But this seems really clunky, especially if there are a lot of operations being performed.

I require the custom rows to be stored in a List or something similar, as I pass this collection around to other areas of my program to be operated on. And I can build this list in the background without having to initialize any UI elements. If I pass around the Rows collection, I keep having to do things like datagridview1.Rows.Cast<CustomRowClass>.someFunctionHere(), which I would prefer to avoid.

Read Entire Article