A silly listview question
-
Ok, I am trying to retrieve a list of names from the database and based upon the number of rows retrieved from the DB, I am trying to do the following: 1. Instantiate a array of command buttons. 2. Add those command buttons to the list view. I am assuming step 2 is possible since the item property is a collection of objects, I can add anything I want to add to it. Well it works fine except instead of actual command buttons, I am seeing the following , "System.windows.forms.Buttons, Text="rwqr"" What am i doing wrong.
-
Ok, I am trying to retrieve a list of names from the database and based upon the number of rows retrieved from the DB, I am trying to do the following: 1. Instantiate a array of command buttons. 2. Add those command buttons to the list view. I am assuming step 2 is possible since the item property is a collection of objects, I can add anything I want to add to it. Well it works fine except instead of actual command buttons, I am seeing the following , "System.windows.forms.Buttons, Text="rwqr"" What am i doing wrong.
What you are trying to do is not directly possible with the listview provided with .NET. The items collection is a collection of data associated with each element in the list, not a collection of controls to be displayed within the list. By default, if no string is supplied when adding items to the collection the objects ToString method is used to get the string to display. This is why you are getting the output you are getting. There are articles here on Code Project that show listview implementations that are capable of docking other controls within the listview. Note that it's not something you will be able to do with a trivial amount of code (though not an unobtainable goal either).