In my case, I started off with a requirement that some of the
DataGridViews in my application must display row numbers in the row header column. To implement that functionality, I turned to Daniel Soper’s excellent article entitled Automatically Adding Numbers to the Rows in a DataGridView. Following Daniel’s example, I was able to create a subclass of
DataGridView to add this row numbering behaviour to my
Unfortunately, as all software developers know, “Change is the only constant” (Heraclitus). Sure enough, my requirements changed and I suddenly needed to add the ability to sort rows in some
DataGridViews by using drag and drop techniques. Again, Daniel Soper provided a solution in his article Custom Row and Column Drag and Drop Reordering Operations with the DataGridView. The problem is, some of my
DataGridViews needed row numbering, others needed drag and drop sorting, others needed both behaviors and still others needed neither behavior.
To make matters worse, soon after I received yet another
DataGridView requirement: the ability to filter the data. The solution for that requirement was provided by Robert Rohde in his article DataGrid with built-in filter functionality. The problem was, how could I combine all of these behaviors without having to create umpteen different subclasses for every combination of those behaviors?