Feeding a custom class to a ListView

I have a ListView control where I initially just added ListViewItem whose content was populated from a custom class I wrote, called "IPrintDocument".

Now I would like to feed IPrintDocument instances as DataSource for those ListViewItems, telling the ListView which fields of the IPrintDocument will be displayed in each column; the reason I am doing this, is that when interacting with the ListView I need the original IPrintDocument class to go ahead with the application.


So, is there a way to keep the original class as DataSource of each ListView item?
LVL 1
Emanuele_CiriachiAsked:
Who is Participating?
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
I'm not sure you can bind a data source to a ListView, you might need to use a DataGridView, or check out this article on creating your own List View control, inheriting from System.Windows.Forms.ListView, which will support data binding: http://www.codeproject.com/KB/list/ListView_DataBinding.aspx
0
 
kaylanreilorCommented:
Just make sure that your custom class implements the IList interface. So for example, you could have your own class owning the data and bind an array of these objects to the control. Databing is a wide subject. There is, among others, an article here : http://msdn.microsoft.com/en-us/library/ms951295.aspx.
0
 
Emanuele_CiriachiAuthor Commented:
Thank you, I will give it a shot right now.
0
 
Emanuele_CiriachiAuthor Commented:
tgerbert,

I found out that your approach is working. I am building my own custom extension of ListView - if it works, the points are yours.
0
 
Emanuele_CiriachiAuthor Commented:
Not so easy to follow, but that is not your fault. Thanks for leading me in the right direction.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.