Tommy1968

Dear all

I have problem about binding data. I use binding navigator "bnTxnAll" with binding source "bsTxnAll". Now, I just want to handle something whenever bnTxnAll move to new record. So, I use bsTxnAll_PositionChanged and it works fine unless I want to handle it first time on record one. And after I bind datasource with bsTxnAll, there is an error occur on line which has following code:

Dim currrow As DataRowView = CType(bsTxnAll.Current, DataRowView)

It says "Unable to cast object of type 'System.Data.DataViewManagerListItemTypeDescriptor' to type 'System.Data.DataRowView'.

It seems that when work at PositionChaged on binding, it still in binding process, so please help suggest if there any event I can use when "bsTxnAll" complete it binding and move to record one. (I have tried DataBindingComplete, it doesn't work either.).

Best Regards,

Tom.




Re: Windows Forms Data Controls and Databinding Problem with PositionChanged event.

Ken Tucker

Why not check and see if the current is datarowview before trying to use Ctype

Code Snippet

if typeof bsTxnAll.Current is DataRowView then

Dim currrow As DataRowView = CType(bsTxnAll.Current, DataRowView)






Re: Windows Forms Data Controls and Databinding Problem with PositionChanged event.

Tommy1968

Thanx for your response. Yes, I should check if it is type of DataRowView. But the point is while I move around binding source using navigator, I can use type of DataRowView but if I want to use type of DataRowView at first time it initialize bindingsource or having a filter, how can I do it. Maybe I should use other event than PositionChanged. Do you understand what I mean And do you have any idea for this






Re: Windows Forms Data Controls and Databinding Problem with PositionChanged event.

Tommy1968

I've got it. I find that when I first bind bindingsource with following order:

bsTxnAll.DataSource = ds

bsTxnAll.DataMember = "TXN_ALL"

then event PositionChanged of bsTxnAll is fired on binding datasource with ds without knowing table they are going to use so bsTxn.Current is of course cannot refer to row of the table but when I change order to.

bsTxnAll.DataMember="TXN_ALL"

bsTxnAll.DataSource=ds

then it fires after knowing that table is "TXN_ALL", so it work!!

Thanx.

Tom.