Hiya,

I'm mucking around with .net 2, and experimenting with the BindingSource
control. I've set the datasource to a dataset and set the datamember
property as the table (or perhaps i've directly set the datasource to
the table and left the datamember as null). When I run the Clear()
method on the BindingSource, I get an exception from the runtime saying
that the clear method cannot be used on the underlying datasource.

Any ideas what I'm doign wrong?

Thanks

Re: BindingSource.Clear method by Bart

Bart
Sat Nov 26 06:52:02 CST 2005

Hi,

"Isaac Abraham" <noone@nowhere.com> wrote in message
news:11ofgg836mu9356@corp.supernews.com...
> Hiya,
>
> I'm mucking around with .net 2, and experimenting with the BindingSource
> control. I've set the datasource to a dataset and set the datamember
> property as the table (or perhaps i've directly set the datasource to the
> table and left the datamember as null). When I run the Clear() method on
> the BindingSource, I get an exception from the runtime saying that the
> clear method cannot be used on the underlying datasource.
>
> Any ideas what I'm doign wrong?

I don't think you're doing anything wrong, it just can't be done. You have
to Clear the underlying DataTable instead.

HTH,
Greetings


>
> Thanks



Re: BindingSource.Clear method by Paul

Paul
Sat Nov 26 07:33:02 CST 2005


See this
(http://msdn2.microsoft.com/library/system.windows.forms.bindingsource.clear.aspx)
example where the table is assigned to the BindingSource.DataSource
property. Internally the table its DataRow collection is bound to the
connector. The Clear operation now deletes all data rows from your table.



###
Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/





"Isaac Abraham" <noone@nowhere.com> wrote in message
news:11ofgg836mu9356@corp.supernews.com...
> Hiya,
>
> I'm mucking around with .net 2, and experimenting with the BindingSource
> control. I've set the datasource to a dataset and set the datamember
> property as the table (or perhaps i've directly set the datasource to the
> table and left the datamember as null). When I run the Clear() method on
> the BindingSource, I get an exception from the runtime saying that the
> clear method cannot be used on the underlying datasource.
>
> Any ideas what I'm doign wrong?
>
> Thanks
>




Re: BindingSource.Clear method by Bart

Bart
Sat Nov 26 08:04:55 CST 2005

Hi,

"Paul Gielens" <pgielens@gmail.com.nospam> wrote in message
news:uYYHv3o8FHA.3200@TK2MSFTNGP11.phx.gbl...
>
> See this
> (http://msdn2.microsoft.com/library/system.windows.forms.bindingsource.clear.aspx)
> example where the table is assigned to the BindingSource.DataSource
> property. Internally the table its DataRow collection is bound to the
> connector. The Clear operation now deletes all data rows from your table.

I don't see an example. And when you bind a DataTable then it's internally
bound to the DefaultView (DataView).

A DataTable isn't directly bindable because it doesn't implement IList, it
does implement IListSource which provides the DefaultView.

DataTable dt = new DataTable();
dt.Columns.Add( "test", typeof(string) );
BindingSource bs = new BindingSource(dt, "");
Console.WriteLine( bs.List.GetType() ); // prints DataView
Console.WriteLine( bs.List == dt.DefaultView ); // prints true


Greetings

>
>
>
> ###
> Best regards,
> Paul Gielens
>
> Visit my blog @ http://weblogs.asp.net/pgielens/
>
>
>
>
>
> "Isaac Abraham" <noone@nowhere.com> wrote in message
> news:11ofgg836mu9356@corp.supernews.com...
>> Hiya,
>>
>> I'm mucking around with .net 2, and experimenting with the BindingSource
>> control. I've set the datasource to a dataset and set the datamember
>> property as the table (or perhaps i've directly set the datasource to the
>> table and left the datamember as null). When I run the Clear() method on
>> the BindingSource, I get an exception from the runtime saying that the
>> clear method cannot be used on the underlying datasource.
>>
>> Any ideas what I'm doign wrong?
>>
>> Thanks
>>
>
>
>



Re: BindingSource.Clear method by Paul

Paul
Sat Nov 26 09:54:52 CST 2005


This showed up while inspecting the DataView class with reflector:
void IList.Clear()
{
throw ExceptionBuilder.CanNotClear();
}public static Exception CanNotClear()
{
return
ExceptionBuilder._Argument(Res.GetString("DataView_CanNotClear"));
}

I was assuming that the ListDictionaryInternal collection class which is
being used inside the DataView class was capable of clearing its values, and
so it seems with reflector. What I overlooked is the DataView class relying
on the IBindingListView (inheriting IBindingList and IList) contract and
thus implements the Clear operation.

Sorry for the wrong link... this would be the correct one
http://msdn2.microsoft.com/library/system.windows.forms.bindingsource.list.aspx.
Hope this clears things up.

###
Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/


"Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message
news:uZGUrKp8FHA.3880@TK2MSFTNGP12.phx.gbl...
>
> Hi,
>
> "Paul Gielens" <pgielens@gmail.com.nospam> wrote in message
> news:uYYHv3o8FHA.3200@TK2MSFTNGP11.phx.gbl...
>>
>> See this
>> (http://msdn2.microsoft.com/library/system.windows.forms.bindingsource.clear.aspx)
>> example where the table is assigned to the BindingSource.DataSource
>> property. Internally the table its DataRow collection is bound to the
>> connector. The Clear operation now deletes all data rows from your table.
>
> I don't see an example. And when you bind a DataTable then it's
> internally bound to the DefaultView (DataView).
>
> A DataTable isn't directly bindable because it doesn't implement IList, it
> does implement IListSource which provides the DefaultView.
>
> DataTable dt = new DataTable();
> dt.Columns.Add( "test", typeof(string) );
> BindingSource bs = new BindingSource(dt, "");
> Console.WriteLine( bs.List.GetType() ); // prints DataView
> Console.WriteLine( bs.List == dt.DefaultView ); // prints true
>
>
> Greetings
>