Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.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
 
Old October 22nd, 2003, 08:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Data Grid editing of class

Hello,

I got the answer to data binding to a class. What I want to be able to do also is to edit the data grid, which calls an update method to the class, similar to how a data grid can update a data set through the data adapter.

Can I do this?

Thanks.
__________________
Brian
 
Old October 22nd, 2003, 10:12 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The datagrid_UpdateCommand handler would need to do what you want.
Usually, you would need to reload a single instance of the class that is in the collection that you are binding to. So you reload one instance, then modify any properties that correspond to changed fields in the datagrid, then you can call the classes update method. This at least how I have done this type of operation. It's entirely likely that there is a more elegant way to do this however.

If you follow the standard procedure for loading and binding data to a datagrid, then you will only have loaded your custom collection once when the page was first loaded and bound this to the grid. Any succeeding operations with the datagrid will be based on the data stored in the grid's viewstate. So you would need to make sure that you have stored some kind of key to the data that this class relates to so you can then reload the class in order to update it.

Maybe this will provide a better explanation (each step is a single page hit):

Step 1 (first load):
- Load collection of classes (from database?)
- Setup datagrid being sure to save some key to the data records

Step 1a (user actions):
- User clicked "Edit" on a record

Step 2 (postback, datagrid.EditCommand event fires):
- Set EditItemIndex to chosen row index
- rebind grid to redraw grid in edit mode

Step 2a (user actions):
- Enter changed values
- Click "Update" button

Step 3:
- Load class instance based on key from grid record
- Update class properties based on updated fields in grid
- call class.Update() method.
- Clear edit index
- Rebind grid

Peter
 
Old October 22nd, 2003, 11:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I'm assuming you are referring to ASP.NET, is it possible for a VB.NET data grid, as they are fundamentally different?
 
Old October 22nd, 2003, 12:38 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Terribly sorry , I'm so used to replying to ASP.Net threads. (1 Dope slap for me...)

I guess it would be somewhat different because of the scope issue. If you left the grid source (collection) within the scope of execution, you should be able to reference one class in the collection based on the edit row index of the grid as they could match up one-to-one. You could then just refer to it that way, set properties and call the update method.

I haven't worked with grids in a forms app so I can't supply more than my thoughts on it.

Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
grid view row editing event fired after postback sasidhar79 ASP.NET 2.0 Professional 0 January 30th, 2007 08:17 PM
Editing Grid with Checkboxes busher ASP.NET 1.0 and 1.1 Basics 4 April 28th, 2005 04:45 AM
Data Grid Editing in C# bmains C# 1 December 16th, 2004 04:23 AM
What is the code for editing data bisigreat VB How-To 2 August 19th, 2004 03:06 AM





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