Hi,
[quoted text, click to view] "Hcan" <hcan@hotmail.com> wrote in message
news:FmvEe.142596$dP1.495964@newsc.telia.net...
>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?
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] >
>
>
> -H
>
>
>
>