S
Scott M.
The difference is that you are referring to 2 different listbox controls.
In a Windows Forms project, you are using the System.Windows.Forms.Listbox
control, which has an Items collection that exposes an Add method. This Add
method only allows Objects to be passed to it and a Folder is an Object, so
your syntax: lstFolders.Items.Add(folder); works just fine.
In an ASP.NET Web Project, you are using the
System.Web.UI.WebConrols.Listbox control, which also exposes an Items
collection that has an Add method as well. But, this Add method only
accepts ListItem objects or Strings. Since your Folder is not a ListItem
object, you must treat it as a string, hence ToString is needed.
The bottom line is that in an ASP.NET Web application, you will be using
different controls than in a Windows Forms application and although you will
see controls that look the same in both kinds of projects, they are not the
same controls and may have differences between them.
-Scott
In a Windows Forms project, you are using the System.Windows.Forms.Listbox
control, which has an Items collection that exposes an Add method. This Add
method only allows Objects to be passed to it and a Folder is an Object, so
your syntax: lstFolders.Items.Add(folder); works just fine.
In an ASP.NET Web Project, you are using the
System.Web.UI.WebConrols.Listbox control, which also exposes an Items
collection that has an Add method as well. But, this Add method only
accepts ListItem objects or Strings. Since your Folder is not a ListItem
object, you must treat it as a string, hence ToString is needed.
The bottom line is that in an ASP.NET Web application, you will be using
different controls than in a Windows Forms application and although you will
see controls that look the same in both kinds of projects, they are not the
same controls and may have differences between them.
-Scott