I am using the following two methods to persist column information about a DataGridView and a ListView.
I notice the methods are very similar and in fact I use the same data structure to store the column settings in. The properties I am storing for each column are things like, Visible, Width, DisplayIndex
How can I re-write this so I have a single function that can handle a DataGridView or a ListView?
I have thought about investigating whether both DataGridView and ListView inherit from a common class or implement a common interface – but I am not sure how to find this out.
Also I have thought about extending each class to implement a common interface… but I am not sure how to proceed.
public void SaveDataGridView ( DataGridView view)
{
foreach (DataGridViewColumn col in view.Columns)
{
// save properties
}
}
public void SaveDataListView(ListView view)
{
foreach (ColumnHeader col in view.Columns)
{
// save properties
}
}
No way until use
dynamickeyword what will not increase the performance.DataGridView.Columns and ListView.Columns have no common base type (except
IList, try but I doubt about any luck). Neither ColumnHeader and DataGridViewColumn have too.