Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 22nd, 2003, 08:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
Reply With Quote
  #2 (permalink)  
Old October 22nd, 2003, 10:12 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old October 22nd, 2003, 11:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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?
Reply With Quote
  #4 (permalink)  
Old October 22nd, 2003, 12:38 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:32 PM.


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