PC Review


Reply
Thread Tools Rate Thread

BindingSource.Add raises error

 
 
Simon
Guest
Posts: n/a
 
      7th Dec 2005
I have a combobox on a form bound to a bindingSource. DataSource is
derived from BindingList as follows:

public class RendererList : BindingList<RendererListItem> {

public RendererList() {
Add(new RendererListItem("Active Server Pages"));
}

}

In my form I am calling the Add method to set the source

rendererListBindingSource.Add(_renList);

_renList is an instance of RendererList which is instantiated at declaration

ie RenderList _renList = new RenderList();

I am getting the error:

InvalidOperationException : Objects added to a BindingSource's list must
all be of the same type.

I've had this error before when I tried to add a collection to the
bindingSource which WASN'T derived from BindingList.

I appreciate this isn't srictly ADO.NET but I seem to find that the best
advice about databinding can be found in this group.

Any ideas.

Many Thanks

Simon
 
Reply With Quote
 
 
 
 
Bart Mermuys
Guest
Posts: n/a
 
      7th Dec 2005
Hi,

"Simon" <(E-Mail Removed)> wrote in message
news:%23NaYCpz%(E-Mail Removed)...
>I have a combobox on a form bound to a bindingSource. DataSource is derived
>from BindingList as follows:
>
> public class RendererList : BindingList<RendererListItem> {
>
> public RendererList() {
> Add(new RendererListItem("Active Server Pages"));
> }
>
> }
>
> In my form I am calling the Add method to set the source
>
> rendererListBindingSource.Add(_renList);


You should set the DataSource :
renderListBindingSource.DataSource = _renList;

rendererListBindingSource.Add is for adding items to the list the
rendererListBindingSource is backing.

HTH,
Greetings

>
> _renList is an instance of RendererList which is instantiated at
> declaration
>
> ie RenderList _renList = new RenderList();
>
> I am getting the error:
>
> InvalidOperationException : Objects added to a BindingSource's list must
> all be of the same type.
>
> I've had this error before when I tried to add a collection to the
> bindingSource which WASN'T derived from BindingList.
>
> I appreciate this isn't srictly ADO.NET but I seem to find that the best
> advice about databinding can be found in this group.
>
> Any ideas.
>
> Many Thanks
>
> Simon



 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      7th Dec 2005
Thanks Bart

Simon

Bart Mermuys wrote:
> Hi,
>
> "Simon" <(E-Mail Removed)> wrote in message
> news:%23NaYCpz%(E-Mail Removed)...
>
>>I have a combobox on a form bound to a bindingSource. DataSource is derived

>
>>from BindingList as follows:

>
>>public class RendererList : BindingList<RendererListItem> {
>>
>>public RendererList() {
>>Add(new RendererListItem("Active Server Pages"));
>>}
>>
>>}
>>
>>In my form I am calling the Add method to set the source
>>
>>rendererListBindingSource.Add(_renList);

>
>
> You should set the DataSource :
> renderListBindingSource.DataSource = _renList;
>
> rendererListBindingSource.Add is for adding items to the list the
> rendererListBindingSource is backing.
>
> HTH,
> Greetings
>
>
>>_renList is an instance of RendererList which is instantiated at
>>declaration
>>
>>ie RenderList _renList = new RenderList();
>>
>>I am getting the error:
>>
>>InvalidOperationException : Objects added to a BindingSource's list must
>>all be of the same type.
>>
>>I've had this error before when I tried to add a collection to the
>>bindingSource which WASN'T derived from BindingList.
>>
>>I appreciate this isn't srictly ADO.NET but I seem to find that the best
>>advice about databinding can be found in this group.
>>
>>Any ideas.
>>
>>Many Thanks
>>
>>Simon

>
>
>

 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      8th Dec 2005
Hi Bart,

That's got rid of my error so now the application starts and the form
displays correctly. However, if I now select the option (the only one at
the moment, although there will be more), I can't leave the combo box.
It has grabbed the focus and refuses to let go. Even attempting to close
the application with the Close Box refuses to respond.

Any ideas?

Simon

Bart Mermuys wrote:
> Hi,
>
> "Simon" <(E-Mail Removed)> wrote in message
> news:%23NaYCpz%(E-Mail Removed)...
>
>>I have a combobox on a form bound to a bindingSource. DataSource is derived

>
>>from BindingList as follows:

>
>>public class RendererList : BindingList<RendererListItem> {
>>
>>public RendererList() {
>>Add(new RendererListItem("Active Server Pages"));
>>}
>>
>>}
>>
>>In my form I am calling the Add method to set the source
>>
>>rendererListBindingSource.Add(_renList);

>
>
> You should set the DataSource :
> renderListBindingSource.DataSource = _renList;
>
> rendererListBindingSource.Add is for adding items to the list the
> rendererListBindingSource is backing.
>
> HTH,
> Greetings
>
>
>>_renList is an instance of RendererList which is instantiated at
>>declaration
>>
>>ie RenderList _renList = new RenderList();
>>
>>I am getting the error:
>>
>>InvalidOperationException : Objects added to a BindingSource's list must
>>all be of the same type.
>>
>>I've had this error before when I tried to add a collection to the
>>bindingSource which WASN'T derived from BindingList.
>>
>>I appreciate this isn't srictly ADO.NET but I seem to find that the best
>>advice about databinding can be found in this group.
>>
>>Any ideas.
>>
>>Many Thanks
>>
>>Simon

>
>
>

 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      8th Dec 2005
Hi,

"Simon" <(E-Mail Removed)> wrote in message
news:eqQ8GY%23%(E-Mail Removed)...
> Hi Bart,
>
> That's got rid of my error so now the application starts and the form
> displays correctly. However, if I now select the option (the only one at
> the moment, although there will be more), I can't leave the combo box. It
> has grabbed the focus and refuses to let go. Even attempting to close the
> application with the Close Box refuses to respond.


This looks like setting e.Cancel to true inside a Validating event handler.
I don't think it's related to the DataSource, but simple bindings can do
this (Text, SelectedIndex, SelectedValue, etc):
ComboBox1.DataBindings.Add( .... );

If you have added simple bindings (designer or code), then remove them and
see if it helps.

If that doesn't help please provide more information, what are you exactly
binding and how...

HTH,
Greetings

>
> Any ideas?
>
> Simon
>
> Bart Mermuys wrote:
>> Hi,
>>
>> "Simon" <(E-Mail Removed)> wrote in message
>> news:%23NaYCpz%(E-Mail Removed)...
>>
>>>I have a combobox on a form bound to a bindingSource. DataSource is
>>>derived

>>
>>>from BindingList as follows:

>>
>>>public class RendererList : BindingList<RendererListItem> {
>>>
>>>public RendererList() {
>>>Add(new RendererListItem("Active Server Pages"));
>>>}
>>>
>>>}
>>>
>>>In my form I am calling the Add method to set the source
>>>
>>>rendererListBindingSource.Add(_renList);

>>
>>
>> You should set the DataSource :
>> renderListBindingSource.DataSource = _renList;
>>
>> rendererListBindingSource.Add is for adding items to the list the
>> rendererListBindingSource is backing.
>>
>> HTH,
>> Greetings
>>
>>
>>>_renList is an instance of RendererList which is instantiated at
>>>declaration
>>>
>>>ie RenderList _renList = new RenderList();
>>>
>>>I am getting the error:
>>>
>>>InvalidOperationException : Objects added to a BindingSource's list must
>>>all be of the same type.
>>>
>>>I've had this error before when I tried to add a collection to the
>>>bindingSource which WASN'T derived from BindingList.
>>>
>>>I appreciate this isn't srictly ADO.NET but I seem to find that the best
>>>advice about databinding can be found in this group.
>>>
>>>Any ideas.
>>>
>>>Many Thanks
>>>
>>>Simon

>>
>>


 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      8th Dec 2005
Hi Bart,

Yes that's fixed it but not a full solution. Probably helps if I tell
you what I'm doing.

I have a set of controls on a form that are bound to an underlying
object instance. I have created a datasource from this object (class to
be specific) and bound the controls to this datasource. Hence the
bindingSource has been added to the component tray on the form.

This is fine for the simple control (text boxes etc). I also have a
datagridview which is bound to a collection within this underlying
object and indeed that is working fine.

I have two properties on my underlying object DatabaseRenderer and
Renderer that just take a string value. I have two combo boxes on the
form that allow the user to select options for these properties. So I'm
trying to fill the comboboxes with some values and then assign the
selectedvalue back to the underlying property. When I save and reload
this file (by serilaizing the underlying object) I want the correct
option to be selected in the combobox.

At the moment I have two collection classes derived from BindingList to
fill these combo boxes and the constructor for these collection classes
populates the item to appear in the list. I'm not precious about this
design (in fact in seems a bit flakey to me), so am open to any other
suggestion about how to fill the boxes and bind the selected item to the
underlying object.

Hope this provides enough info.

Thanks again for your help

Simon


Bart Mermuys wrote:
> Hi,
>
> "Simon" <(E-Mail Removed)> wrote in message
> news:eqQ8GY%23%(E-Mail Removed)...
>
>>Hi Bart,
>>
>>That's got rid of my error so now the application starts and the form
>>displays correctly. However, if I now select the option (the only one at
>>the moment, although there will be more), I can't leave the combo box. It
>>has grabbed the focus and refuses to let go. Even attempting to close the
>>application with the Close Box refuses to respond.

>
>
> This looks like setting e.Cancel to true inside a Validating event handler.
> I don't think it's related to the DataSource, but simple bindings can do
> this (Text, SelectedIndex, SelectedValue, etc):
> ComboBox1.DataBindings.Add( .... );
>
> If you have added simple bindings (designer or code), then remove them and
> see if it helps.
>
> If that doesn't help please provide more information, what are you exactly
> binding and how...
>
> HTH,
> Greetings
>
>
>>Any ideas?
>>
>>Simon
>>
>>Bart Mermuys wrote:
>>
>>>Hi,
>>>
>>>"Simon" <(E-Mail Removed)> wrote in message
>>>news:%23NaYCpz%(E-Mail Removed)...
>>>
>>>
>>>>I have a combobox on a form bound to a bindingSource. DataSource is
>>>>derived
>>>
>>>>from BindingList as follows:
>>>
>>>
>>>>public class RendererList : BindingList<RendererListItem> {
>>>>
>>>>public RendererList() {
>>>>Add(new RendererListItem("Active Server Pages"));
>>>>}
>>>>
>>>>}
>>>>
>>>>In my form I am calling the Add method to set the source
>>>>
>>>>rendererListBindingSource.Add(_renList);
>>>
>>>
>>>You should set the DataSource :
>>>renderListBindingSource.DataSource = _renList;
>>>
>>>rendererListBindingSource.Add is for adding items to the list the
>>>rendererListBindingSource is backing.
>>>
>>>HTH,
>>>Greetings
>>>
>>>
>>>
>>>>_renList is an instance of RendererList which is instantiated at
>>>>declaration
>>>>
>>>>ie RenderList _renList = new RenderList();
>>>>
>>>>I am getting the error:
>>>>
>>>>InvalidOperationException : Objects added to a BindingSource's list must
>>>>all be of the same type.
>>>>
>>>>I've had this error before when I tried to add a collection to the
>>>>bindingSource which WASN'T derived from BindingList.
>>>>
>>>>I appreciate this isn't srictly ADO.NET but I seem to find that the best
>>>>advice about databinding can be found in this group.
>>>>
>>>>Any ideas.
>>>>
>>>>Many Thanks
>>>>
>>>>Simon
>>>
>>>

>

 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      8th Dec 2005
Hi,

"Simon" <(E-Mail Removed)> wrote in message
news:esEieMA$(E-Mail Removed)...
> Hi Bart,
>
> Yes that's fixed it but not a full solution. Probably helps if I tell you
> what I'm doing.
>
> I have a set of controls on a form that are bound to an underlying object
> instance. I have created a datasource from this object (class to be
> specific) and bound the controls to this datasource. Hence the
> bindingSource has been added to the component tray on the form.
>
> This is fine for the simple control (text boxes etc). I also have a
> datagridview which is bound to a collection within this underlying object
> and indeed that is working fine.
>
> I have two properties on my underlying object DatabaseRenderer and
> Renderer that just take a string value. I have two combo boxes on the form
> that allow the user to select options for these properties. So I'm trying
> to fill the comboboxes with some values and then assign the selectedvalue
> back to the underlying property. When I save and reload this file (by
> serilaizing the underlying object) I want the correct option to be
> selected in the combobox.
>
> At the moment I have two collection classes derived from BindingList to
> fill these combo boxes and the constructor for these collection classes
> populates the item to appear in the list. I'm not precious about this
> design (in fact in seems a bit flakey to me),


It's not that bad, if they don't change often, otherwise you could
serialize/deserialize them too, instead of filling in the c'tor.

> so am open to any other suggestion about how to fill the boxes and bind
> the selected item to the underlying object.
>
> Hope this provides enough info.


What you describe should basicly work, so something must be wrong.

1
First of all, are you using the right ValueMember and the right DataSource
for the simple binding:
(could be from designer or from code)
RendererComboBox.DataSource = rendererListBindingSource;
RendererComboBox.DisplayMember = "...";
RendererComboBox.ValueMember = "(*)";
RendererComboBox.Add("SelectedValue", masterObjectBindingSource, "Renderer")

(*) ValueMember must be set to a property that has the same type as
MasterObject.Renderer.

2
And check if there no problems with the property-get and -set for the
MasterObject.Renderer and MasterObject.DataBaseRenderer.

If you bind to "SelectedValue" and you can not move out of the ComboBox,
then a problem occured while DataBinding tries to persist SelectedValue to
the underlying object (property).


HTH,
Greetings


>
> Thanks again for your help
>
> Simon
>
>
> Bart Mermuys wrote:
>> Hi,
>>
>> "Simon" <(E-Mail Removed)> wrote in message
>> news:eqQ8GY%23%(E-Mail Removed)...
>>
>>>Hi Bart,
>>>
>>>That's got rid of my error so now the application starts and the form
>>>displays correctly. However, if I now select the option (the only one at
>>>the moment, although there will be more), I can't leave the combo box. It
>>>has grabbed the focus and refuses to let go. Even attempting to close the
>>>application with the Close Box refuses to respond.

>>
>>
>> This looks like setting e.Cancel to true inside a Validating event
>> handler. I don't think it's related to the DataSource, but simple
>> bindings can do this (Text, SelectedIndex, SelectedValue, etc):
>> ComboBox1.DataBindings.Add( .... );
>>
>> If you have added simple bindings (designer or code), then remove them
>> and see if it helps.
>>
>> If that doesn't help please provide more information, what are you
>> exactly binding and how...
>>
>> HTH,
>> Greetings
>>
>>
>>>Any ideas?
>>>
>>>Simon
>>>
>>>Bart Mermuys wrote:
>>>
>>>>Hi,
>>>>
>>>>"Simon" <(E-Mail Removed)> wrote in message
>>>>news:%23NaYCpz%(E-Mail Removed)...
>>>>
>>>>
>>>>>I have a combobox on a form bound to a bindingSource. DataSource is
>>>>>derived
>>>>
>>>>>from BindingList as follows:
>>>>
>>>>
>>>>>public class RendererList : BindingList<RendererListItem> {
>>>>>
>>>>>public RendererList() {
>>>>>Add(new RendererListItem("Active Server Pages"));
>>>>>}
>>>>>
>>>>>}
>>>>>
>>>>>In my form I am calling the Add method to set the source
>>>>>
>>>>>rendererListBindingSource.Add(_renList);
>>>>
>>>>
>>>>You should set the DataSource :
>>>>renderListBindingSource.DataSource = _renList;
>>>>
>>>>rendererListBindingSource.Add is for adding items to the list the
>>>>rendererListBindingSource is backing.
>>>>
>>>>HTH,
>>>>Greetings
>>>>
>>>>
>>>>
>>>>>_renList is an instance of RendererList which is instantiated at
>>>>>declaration
>>>>>
>>>>>ie RenderList _renList = new RenderList();
>>>>>
>>>>>I am getting the error:
>>>>>
>>>>>InvalidOperationException : Objects added to a BindingSource's list
>>>>>must all be of the same type.
>>>>>
>>>>>I've had this error before when I tried to add a collection to the
>>>>>bindingSource which WASN'T derived from BindingList.
>>>>>
>>>>>I appreciate this isn't srictly ADO.NET but I seem to find that the
>>>>>best advice about databinding can be found in this group.
>>>>>
>>>>>Any ideas.
>>>>>
>>>>>Many Thanks
>>>>>
>>>>>Simon
>>>>
>>>>

>>



 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      9th Dec 2005
Hi Bart,

Bart Mermuys wrote:
> Hi,
>
> "Simon" <(E-Mail Removed)> wrote in message
> news:esEieMA$(E-Mail Removed)...
>
>>Hi Bart,
>>
>>Yes that's fixed it but not a full solution. Probably helps if I tell you
>>what I'm doing.
>>
>>I have a set of controls on a form that are bound to an underlying object
>>instance. I have created a datasource from this object (class to be
>>specific) and bound the controls to this datasource. Hence the
>>bindingSource has been added to the component tray on the form.
>>
>>This is fine for the simple control (text boxes etc). I also have a
>>datagridview which is bound to a collection within this underlying object
>>and indeed that is working fine.
>>
>>I have two properties on my underlying object DatabaseRenderer and
>>Renderer that just take a string value. I have two combo boxes on the form
>>that allow the user to select options for these properties. So I'm trying
>>to fill the comboboxes with some values and then assign the selectedvalue
>>back to the underlying property. When I save and reload this file (by
>>serilaizing the underlying object) I want the correct option to be
>>selected in the combobox.
>>
>>At the moment I have two collection classes derived from BindingList to
>>fill these combo boxes and the constructor for these collection classes
>>populates the item to appear in the list. I'm not precious about this
>>design (in fact in seems a bit flakey to me),

>
>
> It's not that bad, if they don't change often, otherwise you could
> serialize/deserialize them too, instead of filling in the c'tor.
>
>
>>so am open to any other suggestion about how to fill the boxes and bind
>>the selected item to the underlying object.
>>
>>Hope this provides enough info.

>
>
> What you describe should basicly work, so something must be wrong.
>
> 1
> First of all, are you using the right ValueMember and the right DataSource
> for the simple binding:
> (could be from designer or from code)
> RendererComboBox.DataSource = rendererListBindingSource;
> RendererComboBox.DisplayMember = "...";
> RendererComboBox.ValueMember = "(*)";
> RendererComboBox.Add("SelectedValue", masterObjectBindingSource, "Renderer")


I can't find an Add method of the ComboBox?

Simon

>
> (*) ValueMember must be set to a property that has the same type as
> MasterObject.Renderer.
>
> 2
> And check if there no problems with the property-get and -set for the
> MasterObject.Renderer and MasterObject.DataBaseRenderer.
>
> If you bind to "SelectedValue" and you can not move out of the ComboBox,
> then a problem occured while DataBinding tries to persist SelectedValue to
> the underlying object (property).
>
>
> HTH,
> Greetings
>
>
>
>>Thanks again for your help
>>
>>Simon
>>
>>
>>Bart Mermuys wrote:
>>
>>>Hi,
>>>
>>>"Simon" <(E-Mail Removed)> wrote in message
>>>news:eqQ8GY%23%(E-Mail Removed)...
>>>
>>>
>>>>Hi Bart,
>>>>
>>>>That's got rid of my error so now the application starts and the form
>>>>displays correctly. However, if I now select the option (the only one at
>>>>the moment, although there will be more), I can't leave the combo box. It
>>>>has grabbed the focus and refuses to let go. Even attempting to close the
>>>>application with the Close Box refuses to respond.
>>>
>>>
>>>This looks like setting e.Cancel to true inside a Validating event
>>>handler. I don't think it's related to the DataSource, but simple
>>>bindings can do this (Text, SelectedIndex, SelectedValue, etc):
>>>ComboBox1.DataBindings.Add( .... );
>>>
>>>If you have added simple bindings (designer or code), then remove them
>>>and see if it helps.
>>>
>>>If that doesn't help please provide more information, what are you
>>>exactly binding and how...
>>>
>>>HTH,
>>>Greetings
>>>
>>>
>>>
>>>>Any ideas?
>>>>
>>>>Simon
>>>>
>>>>Bart Mermuys wrote:
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>"Simon" <(E-Mail Removed)> wrote in message
>>>>>news:%23NaYCpz%(E-Mail Removed)...
>>>>>
>>>>>
>>>>>
>>>>>>I have a combobox on a form bound to a bindingSource. DataSource is
>>>>>>derived
>>>>>
>>>>>>from BindingList as follows:
>>>>>
>>>>>
>>>>>
>>>>>>public class RendererList : BindingList<RendererListItem> {
>>>>>>
>>>>>>public RendererList() {
>>>>>>Add(new RendererListItem("Active Server Pages"));
>>>>>>}
>>>>>>
>>>>>>}
>>>>>>
>>>>>>In my form I am calling the Add method to set the source
>>>>>>
>>>>>>rendererListBindingSource.Add(_renList);
>>>>>
>>>>>
>>>>>You should set the DataSource :
>>>>>renderListBindingSource.DataSource = _renList;
>>>>>
>>>>>rendererListBindingSource.Add is for adding items to the list the
>>>>>rendererListBindingSource is backing.
>>>>>
>>>>>HTH,
>>>>>Greetings
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>_renList is an instance of RendererList which is instantiated at
>>>>>>declaration
>>>>>>
>>>>>>ie RenderList _renList = new RenderList();
>>>>>>
>>>>>>I am getting the error:
>>>>>>
>>>>>>InvalidOperationException : Objects added to a BindingSource's list
>>>>>>must all be of the same type.
>>>>>>
>>>>>>I've had this error before when I tried to add a collection to the
>>>>>>bindingSource which WASN'T derived from BindingList.
>>>>>>
>>>>>>I appreciate this isn't srictly ADO.NET but I seem to find that the
>>>>>>best advice about databinding can be found in this group.
>>>>>>
>>>>>>Any ideas.
>>>>>>
>>>>>>Many Thanks
>>>>>>
>>>>>>Simon
>>>>>
>>>>>

>
>

 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      9th Dec 2005
Ahhh .. still can't find the Add method, but I've found the problem. It
was to do with the property get/set.

Cheers

Simon

Bart Mermuys wrote:
> Hi,
>
> "Simon" <(E-Mail Removed)> wrote in message
> news:esEieMA$(E-Mail Removed)...
>
>>Hi Bart,
>>
>>Yes that's fixed it but not a full solution. Probably helps if I tell you
>>what I'm doing.
>>
>>I have a set of controls on a form that are bound to an underlying object
>>instance. I have created a datasource from this object (class to be
>>specific) and bound the controls to this datasource. Hence the
>>bindingSource has been added to the component tray on the form.
>>
>>This is fine for the simple control (text boxes etc). I also have a
>>datagridview which is bound to a collection within this underlying object
>>and indeed that is working fine.
>>
>>I have two properties on my underlying object DatabaseRenderer and
>>Renderer that just take a string value. I have two combo boxes on the form
>>that allow the user to select options for these properties. So I'm trying
>>to fill the comboboxes with some values and then assign the selectedvalue
>>back to the underlying property. When I save and reload this file (by
>>serilaizing the underlying object) I want the correct option to be
>>selected in the combobox.
>>
>>At the moment I have two collection classes derived from BindingList to
>>fill these combo boxes and the constructor for these collection classes
>>populates the item to appear in the list. I'm not precious about this
>>design (in fact in seems a bit flakey to me),

>
>
> It's not that bad, if they don't change often, otherwise you could
> serialize/deserialize them too, instead of filling in the c'tor.
>
>
>>so am open to any other suggestion about how to fill the boxes and bind
>>the selected item to the underlying object.
>>
>>Hope this provides enough info.

>
>
> What you describe should basicly work, so something must be wrong.
>
> 1
> First of all, are you using the right ValueMember and the right DataSource
> for the simple binding:
> (could be from designer or from code)
> RendererComboBox.DataSource = rendererListBindingSource;
> RendererComboBox.DisplayMember = "...";
> RendererComboBox.ValueMember = "(*)";
> RendererComboBox.Add("SelectedValue", masterObjectBindingSource, "Renderer")
>
> (*) ValueMember must be set to a property that has the same type as
> MasterObject.Renderer.
>
> 2
> And check if there no problems with the property-get and -set for the
> MasterObject.Renderer and MasterObject.DataBaseRenderer.
>
> If you bind to "SelectedValue" and you can not move out of the ComboBox,
> then a problem occured while DataBinding tries to persist SelectedValue to
> the underlying object (property).
>
>
> HTH,
> Greetings
>
>
>
>>Thanks again for your help
>>
>>Simon
>>
>>
>>Bart Mermuys wrote:
>>
>>>Hi,
>>>
>>>"Simon" <(E-Mail Removed)> wrote in message
>>>news:eqQ8GY%23%(E-Mail Removed)...
>>>
>>>
>>>>Hi Bart,
>>>>
>>>>That's got rid of my error so now the application starts and the form
>>>>displays correctly. However, if I now select the option (the only one at
>>>>the moment, although there will be more), I can't leave the combo box. It
>>>>has grabbed the focus and refuses to let go. Even attempting to close the
>>>>application with the Close Box refuses to respond.
>>>
>>>
>>>This looks like setting e.Cancel to true inside a Validating event
>>>handler. I don't think it's related to the DataSource, but simple
>>>bindings can do this (Text, SelectedIndex, SelectedValue, etc):
>>>ComboBox1.DataBindings.Add( .... );
>>>
>>>If you have added simple bindings (designer or code), then remove them
>>>and see if it helps.
>>>
>>>If that doesn't help please provide more information, what are you
>>>exactly binding and how...
>>>
>>>HTH,
>>>Greetings
>>>
>>>
>>>
>>>>Any ideas?
>>>>
>>>>Simon
>>>>
>>>>Bart Mermuys wrote:
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>"Simon" <(E-Mail Removed)> wrote in message
>>>>>news:%23NaYCpz%(E-Mail Removed)...
>>>>>
>>>>>
>>>>>
>>>>>>I have a combobox on a form bound to a bindingSource. DataSource is
>>>>>>derived
>>>>>
>>>>>>from BindingList as follows:
>>>>>
>>>>>
>>>>>
>>>>>>public class RendererList : BindingList<RendererListItem> {
>>>>>>
>>>>>>public RendererList() {
>>>>>>Add(new RendererListItem("Active Server Pages"));
>>>>>>}
>>>>>>
>>>>>>}
>>>>>>
>>>>>>In my form I am calling the Add method to set the source
>>>>>>
>>>>>>rendererListBindingSource.Add(_renList);
>>>>>
>>>>>
>>>>>You should set the DataSource :
>>>>>renderListBindingSource.DataSource = _renList;
>>>>>
>>>>>rendererListBindingSource.Add is for adding items to the list the
>>>>>rendererListBindingSource is backing.
>>>>>
>>>>>HTH,
>>>>>Greetings
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>_renList is an instance of RendererList which is instantiated at
>>>>>>declaration
>>>>>>
>>>>>>ie RenderList _renList = new RenderList();
>>>>>>
>>>>>>I am getting the error:
>>>>>>
>>>>>>InvalidOperationException : Objects added to a BindingSource's list
>>>>>>must all be of the same type.
>>>>>>
>>>>>>I've had this error before when I tried to add a collection to the
>>>>>>bindingSource which WASN'T derived from BindingList.
>>>>>>
>>>>>>I appreciate this isn't srictly ADO.NET but I seem to find that the
>>>>>>best advice about databinding can be found in this group.
>>>>>>
>>>>>>Any ideas.
>>>>>>
>>>>>>Many Thanks
>>>>>>
>>>>>>Simon
>>>>>
>>>>>

>
>

 
Reply With Quote
 
Bart Mermuys
Guest
Posts: n/a
 
      9th Dec 2005
Hi,

"Simon" <(E-Mail Removed)> wrote in message
news:uTtxzRM$(E-Mail Removed)...
> Ahhh .. still can't find the Add method, but I've found the problem. It
> was to do with the property get/set.


Nice :-)

I meant ComboBox.DataBindings.Add(...) (or from designer), but appearently
it was the property get and set.

Greetings

>
> Cheers
>
> Simon
>
> Bart Mermuys wrote:
>> Hi,
>>
>> "Simon" <(E-Mail Removed)> wrote in message
>> news:esEieMA$(E-Mail Removed)...
>>
>>>Hi Bart,
>>>
>>>Yes that's fixed it but not a full solution. Probably helps if I tell you
>>>what I'm doing.
>>>
>>>I have a set of controls on a form that are bound to an underlying object
>>>instance. I have created a datasource from this object (class to be
>>>specific) and bound the controls to this datasource. Hence the
>>>bindingSource has been added to the component tray on the form.
>>>
>>>This is fine for the simple control (text boxes etc). I also have a
>>>datagridview which is bound to a collection within this underlying object
>>>and indeed that is working fine.
>>>
>>>I have two properties on my underlying object DatabaseRenderer and
>>>Renderer that just take a string value. I have two combo boxes on the
>>>form that allow the user to select options for these properties. So I'm
>>>trying to fill the comboboxes with some values and then assign the
>>>selectedvalue back to the underlying property. When I save and reload
>>>this file (by serilaizing the underlying object) I want the correct
>>>option to be selected in the combobox.
>>>
>>>At the moment I have two collection classes derived from BindingList to
>>>fill these combo boxes and the constructor for these collection classes
>>>populates the item to appear in the list. I'm not precious about this
>>>design (in fact in seems a bit flakey to me),

>>
>>
>> It's not that bad, if they don't change often, otherwise you could
>> serialize/deserialize them too, instead of filling in the c'tor.
>>
>>
>>>so am open to any other suggestion about how to fill the boxes and bind
>>>the selected item to the underlying object.
>>>
>>>Hope this provides enough info.

>>
>>
>> What you describe should basicly work, so something must be wrong.
>>
>> 1
>> First of all, are you using the right ValueMember and the right
>> DataSource for the simple binding:
>> (could be from designer or from code)
>> RendererComboBox.DataSource = rendererListBindingSource;
>> RendererComboBox.DisplayMember = "...";
>> RendererComboBox.ValueMember = "(*)";
>> RendererComboBox.Add("SelectedValue", masterObjectBindingSource,
>> "Renderer")
>>
>> (*) ValueMember must be set to a property that has the same type as
>> MasterObject.Renderer.
>>
>> 2
>> And check if there no problems with the property-get and -set for the
>> MasterObject.Renderer and MasterObject.DataBaseRenderer.
>>
>> If you bind to "SelectedValue" and you can not move out of the ComboBox,
>> then a problem occured while DataBinding tries to persist SelectedValue
>> to the underlying object (property).
>>
>>
>> HTH,
>> Greetings
>>
>>
>>
>>>Thanks again for your help
>>>
>>>Simon
>>>
>>>
>>>Bart Mermuys wrote:
>>>
>>>>Hi,
>>>>
>>>>"Simon" <(E-Mail Removed)> wrote in message
>>>>news:eqQ8GY%23%(E-Mail Removed)...
>>>>
>>>>
>>>>>Hi Bart,
>>>>>
>>>>>That's got rid of my error so now the application starts and the form
>>>>>displays correctly. However, if I now select the option (the only one
>>>>>at the moment, although there will be more), I can't leave the combo
>>>>>box. It has grabbed the focus and refuses to let go. Even attempting to
>>>>>close the application with the Close Box refuses to respond.
>>>>
>>>>
>>>>This looks like setting e.Cancel to true inside a Validating event
>>>>handler. I don't think it's related to the DataSource, but simple
>>>>bindings can do this (Text, SelectedIndex, SelectedValue, etc):
>>>>ComboBox1.DataBindings.Add( .... );
>>>>
>>>>If you have added simple bindings (designer or code), then remove them
>>>>and see if it helps.
>>>>
>>>>If that doesn't help please provide more information, what are you
>>>>exactly binding and how...
>>>>
>>>>HTH,
>>>>Greetings
>>>>
>>>>
>>>>
>>>>>Any ideas?
>>>>>
>>>>>Simon
>>>>>
>>>>>Bart Mermuys wrote:
>>>>>
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>"Simon" <(E-Mail Removed)> wrote in message
>>>>>>news:%23NaYCpz%(E-Mail Removed)...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I have a combobox on a form bound to a bindingSource. DataSource is
>>>>>>>derived
>>>>>>
>>>>>>>from BindingList as follows:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>public class RendererList : BindingList<RendererListItem> {
>>>>>>>
>>>>>>>public RendererList() {
>>>>>>>Add(new RendererListItem("Active Server Pages"));
>>>>>>>}
>>>>>>>
>>>>>>>}
>>>>>>>
>>>>>>>In my form I am calling the Add method to set the source
>>>>>>>
>>>>>>>rendererListBindingSource.Add(_renList);
>>>>>>
>>>>>>
>>>>>>You should set the DataSource :
>>>>>>renderListBindingSource.DataSource = _renList;
>>>>>>
>>>>>>rendererListBindingSource.Add is for adding items to the list the
>>>>>>rendererListBindingSource is backing.
>>>>>>
>>>>>>HTH,
>>>>>>Greetings
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>_renList is an instance of RendererList which is instantiated at
>>>>>>>declaration
>>>>>>>
>>>>>>>ie RenderList _renList = new RenderList();
>>>>>>>
>>>>>>>I am getting the error:
>>>>>>>
>>>>>>>InvalidOperationException : Objects added to a BindingSource's list
>>>>>>>must all be of the same type.
>>>>>>>
>>>>>>>I've had this error before when I tried to add a collection to the
>>>>>>>bindingSource which WASN'T derived from BindingList.
>>>>>>>
>>>>>>>I appreciate this isn't srictly ADO.NET but I seem to find that the
>>>>>>>best advice about databinding can be found in this group.
>>>>>>>
>>>>>>>Any ideas.
>>>>>>>
>>>>>>>Many Thanks
>>>>>>>
>>>>>>>Simon
>>>>>>
>>>>>>

>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: autofilter raises error 1004 Dave Peterson Microsoft Excel Programming 3 12th Oct 2009 02:34 PM
RE: autofilter raises error 1004 OssieMac Microsoft Excel Programming 0 9th Oct 2009 08:19 AM
query name in ado/dao raises error =?Utf-8?B?WWlzTWFu?= Microsoft Access Form Coding 0 21st Jun 2006 05:34 PM
datagrid.Select raises error... SammyBar Microsoft Dot NET Compact Framework 1 23rd Jan 2006 09:24 PM
Unable to run asp.net application, it raises error =?Utf-8?B?c3VkaGVlcg==?= Microsoft ASP .NET 1 11th Apr 2004 06:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 AM.