views:

140

answers:

2

I have a DataGridView (with WinForms) where I'm treating a particular row as a "child" of the row just before it. This means when a user sorts a column, that child row as to stay attached to the parent so it always appears just below it.

I'm overriding the SortCompare method to handle this, but I'm not sure just how to do it. Within SortCompare, I know if the row has a parent row, and if so what that row is. Therefore I want to be able to say, "if row1 has a parent, let the sort result be whatever it would be comparing row1's parent to row2". But how do I accomplish that without explicitly comparing the values myself (which I want to avoid so I don't have to keep track of the data types)? Is the comparer it's using available anywhere? Or is there just a better way to do what I'm trying to accomplish?

A: 

Set SortExpression on the column to any valid column name. It does not have to be itself

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortexpression.aspx

Chris Ballance
sorry, forgot to mention this is WinForms. thanks though.
toasteroven
A: 

I'm guessing you want small groups. Have you looked at the custom DataGridViewGrouper component ?

You could have distinct properties for each row group and use this custom component to create your groups. Each two-row group would have a distinct property that would allow you to group them together. To me, you would have to somehow distinguish individual groups through a distinct tag or property. There is no parent-child relationship in this case, though I don't see that is important since you want to group them.

0A0D