Search Amazon:

How do I end the editing of a cell in the DataGrid?

If a DataGrid cell is in the process of being edited and the cell doesn't loose focus it may not be flagged as changed. For example, you click a cell, change its value, then click the Save button. The value in the DataTable that's bound to the DataGrid may still contain the original value.

The DataGrid's EndEdit method requests an end to the edit operation taking place. EndEdit takes as parameters the DataGridColumnStyle to cease editing, the number of the row to stop editing and a boolean ShouldAbort flag. Set ShouldAbort True if the edit operation should be stopped.

This snippet tells the DataGrid to continue the edit operation by setting the ShouldAbort flag False. In other words, keep the new value. Then the EndCurrentEdit method of the CurrencyManager ends the edit operation. This code would be placed at the top of your Save button's event handler.

    With DataGrid
        .EndEdit(.TableStyles(0).GridColumnStyles(.CurrentCell.ColumnNumber), _
                 .CurrentCell.RowNumber, False)

        Dim cm As CurrencyManager = CType(.BindingContext(.DataSource), CurrencyManager)
        cm.EndCurrentEdit()
        cm.Refresh()
    End With

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms