Wednesday, 15 May 2013

c# - How do I write a method that can take either a DataGridView or a ListView as input? -



c# - How do I write a method that can take either a DataGridView or a ListView as input? -

i using next 2 methods persist column info datagridview , listview.

i notice methods similar , in fact utilize same info construction store column settings in. properties storing each column things like, visible, width, displayindex

how can re-write have single function can handle datagridview or listview?

i have thought investigating whether both datagridview , listview inherit mutual class or implement mutual interface - not sure how find out.

also have thought extending each class implement mutual interface... not sure how 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 utilize dynamic keyword not increment performance.

datagridview.columns , listview.columns have no mutual base of operations type (except ilist, seek uncertainty luck). neither columnheader , datagridviewcolumn have too.

c# .net winforms listview datagridview

No comments:

Post a Comment