Click here to Skip to main content
15,897,141 members
Home / Discussions / C#
   

C#

 
QuestionIs WebProxy class only support HTTP proxy type? Pin
Ronakkumar Patel8-Jun-07 5:50
Ronakkumar Patel8-Jun-07 5:50 
QuestionImage's path Pin
Nine_8-Jun-07 4:34
Nine_8-Jun-07 4:34 
AnswerRe: Image's path Pin
Not Active8-Jun-07 4:53
mentorNot Active8-Jun-07 4:53 
GeneralRe: Image's path Pin
Nine_8-Jun-07 15:56
Nine_8-Jun-07 15:56 
GeneralRe: Image's path Pin
Not Active9-Jun-07 2:23
mentorNot Active9-Jun-07 2:23 
QuestionPrompt user to close outlook during install/uninstall Pin
Aerukull8-Jun-07 4:33
Aerukull8-Jun-07 4:33 
AnswerRe: Prompt user to close outlook during install/uninstall Pin
AikinX9-Jun-07 0:30
AikinX9-Jun-07 0:30 
QuestionIList and BindingSource Problem [modified] Pin
Wjousts8-Jun-07 3:42
Wjousts8-Jun-07 3:42 
I've noticed a odd problem when using a class that implements IList<T> with a BindingSource. I've managed to reproduce the problem with some simple classes. I have a class called BaseClass and several classes that derive from BaseClass called DerivedClass1, DerivedClass2 and DerivedClass3.

Now I create a class to act as a collection of BaseClass objects called BaseClassCollection. BaseClassCollection implements IList<T> and basically just wraps a List<BaseClass> at this point. At this point everything works fine and I can populate the BaseClassCollection with objects of type DerivedClass1, DerivedClass2 and DerivedClass3 to create a heterogenous collection.

Now the problem comes when I try and use BaseClassCollection as a DataSource for a BindingSource. I create a form with a ListBox control with it's DataSource set to a BindingSource. I then set my BindingSource to bind to an empty BaseClassCollection. Then I add three buttons that will add either a DerivedClass1, DerivedClass2 or a DerivedClass3 object to the collection and refreshes the BindingSource. If I add several objects of the same type then I have no problem, but as soon as I try to add a object of a different class I get an exception:



The value "BindingTest.Derived2" is not of type "BindingTest.Derived1" and cannot be used in this generic collection.
Parameter name: value



It seems that when you set the DataSource of the BindingSource to an IList<T> it looks at the first item in the list (let's say it's a DerivedClass1) and assumes that the list is a DerivedClass1 list and won't let you add anything that isn't a DerivedClass1. What it should do is recognize that it's an IList<baseclass> and assume we have a list of BaseClass and thus allow the addition of any class derived from BaseClass. Oddly enough, if I make my BaseClassCollection inherit from List<BaseClass> instead or implementing IList<BaseClass> then it works as expected, but I lose the ability to control the implemenation of the list.

Does anybody know what is happening here? How do I make the BindingSource realize that it's dealing with a collection of BaseClass?



-- modified at 21:21 Friday 8th June, 2007

Fixed by < and > which completely changed the meaning of the question D'Oh! | :doh:
AnswerRe: IList and BindingSource Problem Pin
Wjousts8-Jun-07 15:25
Wjousts8-Jun-07 15:25 
QuestionForm Application with Plugins via assembly loading Pin
ATCsharp8-Jun-07 2:47
ATCsharp8-Jun-07 2:47 
AnswerRe: Form Application with Plugins via assembly loading Pin
ATCsharp8-Jun-07 3:01
ATCsharp8-Jun-07 3:01 
GeneralRe: Form Application with Plugins via assembly loading Pin
Not Active8-Jun-07 3:12
mentorNot Active8-Jun-07 3:12 
GeneralRe: Form Application with Plugins via assembly loading Pin
ATCsharp8-Jun-07 3:23
ATCsharp8-Jun-07 3:23 
GeneralRe: Form Application with Plugins via assembly loading Pin
Not Active8-Jun-07 3:28
mentorNot Active8-Jun-07 3:28 
QuestionPlay MKV files in embedded media player Pin
sypack8-Jun-07 2:16
sypack8-Jun-07 2:16 
AnswerRe: Play MKV files in embedded media player Pin
Bekjong8-Jun-07 2:32
Bekjong8-Jun-07 2:32 
GeneralRe: Play MKV files in embedded media player Pin
sypack8-Jun-07 2:37
sypack8-Jun-07 2:37 
QuestionEncryption and Decryption Pin
M. J. Jaya Chitra8-Jun-07 2:15
M. J. Jaya Chitra8-Jun-07 2:15 
AnswerRe: Encryption and Decryption Pin
Sathesh Sakthivel8-Jun-07 2:19
Sathesh Sakthivel8-Jun-07 2:19 
AnswerRe: Encryption and Decryption Pin
Pixinger778-Jun-07 3:10
Pixinger778-Jun-07 3:10 
GeneralRe: Encryption and Decryption Pin
originSH8-Jun-07 3:48
originSH8-Jun-07 3:48 
AnswerRe: Encryption and Decryption Pin
Russell Jones8-Jun-07 4:39
Russell Jones8-Jun-07 4:39 
QuestionSQL Connection DialogBox Pin
ScottM18-Jun-07 2:07
ScottM18-Jun-07 2:07 
QuestionPacking a class into a byte array - would [Serializable] do the trick? Pin
Dewald8-Jun-07 2:02
Dewald8-Jun-07 2:02 
AnswerRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
AikinX8-Jun-07 2:16
AikinX8-Jun-07 2:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.