Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 2nd, 2004, 01:24 AM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default "Insertat" problem

I need to insert new row into DataGrid to a specified position (not at the end of the table). I tried to use the DataTable.Rows.InsertAt() method which does (almost) exactly what I need. The 'almost' means that the row is added at the end of the table even if I specify an index for the new row.
I have already tried to search the internet and the only solution I have found was to call DataTable.AcceptChanges() method. OK, this works, the row is then realy displayed on the propper position. Problem is that when I try to change some values in that row, the row jumps at the end of the table and an empty row appears at the correct position. If I try to make any other changes into the row (which is ath the bottom now), the application crashes with following exception:

Object reference not set to an instance of an object.
at System.Data.DataRowView.System.ComponentModel.IDat aErrorInfo.get_Error()
....
....
.


how to resolve this problem?
  #2 (permalink)  
Old September 7th, 2006, 10:38 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have to build a new dataview on the altered table (prior to AcceptChanges) and bind the grid to that.

     Dim dv As New DataView(myTable)

     myDatagrid.DataSource = dv
     myDatagrid.DataBind()

First jump off the cliff. You can build your wings on the way down. -- Ray Bradbury






Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.