Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CurrentChanged problem with DataView

Status
Not open for further replies.

FRoeCassNet

Programmer
Feb 8, 2002
147
US
I have a DataGrid that I am binding to a DataView. I setup a handler on the DataView's CurrentChanged event and everything works fine as long as I have the DataView's AllowNew property set to True. If I set it to False, then "sometimes" after reloading the data, the event doesn't get fired anymore. Has anyone seen anythink like this before?

Here's a sample of what I'm doing...
MyView.Table = MyDataSet
MyGrid.DataSource = MyView

--Form Load--
AddHandler Me.BindingContext(MyView).CurrentChanged, AddressOf MyView_CurrentChanged
MyDataset.Merge(<loaded data>)

--Button Click--
MyDataset.Clear()
MyDataset.Merge(<loaded data>)

--MyView_CurrentChanged--
Debug.WriteLine(&quot;Current changed&quot;)

In the Form Load, I set the handler for the view's currentchanged event and load the initial data into the dataset. As I click across rows in the datagrid, the &quot;Current changed&quot; message gets logged. I click a button and clears the dataset and loads in another block of data. I can click on another row and i will log the &quot;Current changed&quot; message, however, if I set they MyView.AllowNew property to False, then when I reload the data (from the button click) it won't trigger the Current changed event. If I click on the grid enough times, it will eventually fire the event and start tracking it again, then if I reload it, it will stop firing again, etc. Sometimes it will keep firing the event after reloads and sometimes it fails to fire it. If the AllowNew is True, then it never fails.

Any help would be appreciated,
Thanks in advance.
 
When you load any data into the data table remove the event handler, re-set it after you have loaded the data.

 
That didn't make any difference. I put a RemoveHandler before the Merge() and then the AddHandler after the Merge(). Still get the same result, works fine for DataView with AllowNew = True, but fails after the reload when AllowNew = False.
 
I found (what appears to be) a workaround for now. After reloading the data, I move the datagrid to the first row (grid.CurrentRowIndex = 0). So far, after doing this, it has continued to fire the event when moving around in the grid. Why the AllowNew makes a difference... only the big guy out West knows for sure.. my best guess is that after reloading the data, the current grid position is pointing to data that no longer exists (okay if you're adding new records) but since the view isn't allowing new records it falls into a black hole somewhere....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top