all groups > dotnet windows forms databinding > july 2005 >
You're in the

dotnet windows forms databinding

group:

Error when casting from CurrencyManager.List to DataView


Error when casting from CurrencyManager.List to DataView Hcan
7/23/2005 5:45:09 PM
dotnet windows forms databinding:
I have a custom collection that inherits from CollectionBase. It is bound to
a DataGrid, and now I want to disable the append row in the DataGrid. The
way I was going to do it is to set the DataView AllowNew property to False.
Something like this:

Dim myCollection as Collection
myCollection.Fill()
DataGrid1.DataSource = myCollection
Dim cm As CurrencyManage
cm = CType(BindingContext(myCollection), CurrencyManager)
Dim dv As DataView
dv = CType(cm.List, DataView)
dv.AllowNew = False

When the cast is from cm.List to DataView, I get this error: Specified cast
is not valid.

Anyone knows why?



-H



Re: Error when casting from CurrencyManager.List to DataView Bart Mermuys
7/24/2005 12:00:00 AM
Hi,

[quoted text, click to view]

A DataView can only be used with a DataTable, not a custom collection.

Your custom collection does implement IList which means that it binds
_directly_ to the grid. And currencyManager.List just returns your custom
collection not a DataView.

Without seeing your custom collection code, i can only guess that you
implemented IBindingList and returned true for IBindingList.AllowNew (and
IBindingList.SupportsChangeNotification), because you're saying the grid
allows new entries to be added.

So, instead of returning true for IBindingList.AllowNew, if you haven't
already, make a get and set for that property, so you can change it, if it
returns false the grid won't allow new entries.


HTH,
greetings

[quoted text, click to view]

Re: Error when casting from CurrencyManager.List to DataView Hcan
7/25/2005 11:26:02 PM
Thanks!

I've implemented the .AllowNew property and it works just perfect!

-H-


"Bart Mermuys" <bmermuys.nospam@hotmail.com> skrev i meddelandet
news:uxiV6PEkFHA.3212@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button