We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GridDataBoundControl on new row event

Thread ID:

Created:

Updated:

Platform:

Replies:

130099 Apr 21,2017 06:32 AM Apr 27,2017 11:59 PM Windows Forms 7
loading
Tags: GridDataBoundGrid(Classic)
Michael K
Asked On April 21, 2017 06:32 AM

Dear All :

If we want to add code (for check current row data) before new row add.
Do  you have event for that 

Just like RowsDeleting event, we can do e.cancel 

Thanks

Arulpriya Ramalingam [Syncfusion]
Replied On April 24, 2017 08:47 AM

Hi Michael, 

Thank you for your interest in Syncfusion products. 

We have analyzed your scenario and we suspect that you are trying to Validate an entire row before adding. By default, in GridDataBoundGridControl the new value will be added to the Grid when the AddNewRow is in EditingMode and it does not have the direct support to validate the entire row.  

Note 
We would like to suggest GridGroupingControl for your requirement. It is used to display the binding source with more flexible manipulation like sorting, grouping, filtering. We have created a simple sample as per requirement using GridGroupingControl. Also GridGroupingControl does not have the direct support to validate an entire row , but this can be achieved by some work around. The CurrentRecordContextChange event can be used to validate an entire row. In that event , you can validate the column values of new record by getting the value using Record.GetValue() method. Please make use of below code and sample, 
 
Code snippet 
//Event Triggering 
this.gridGroupingControl1.CurrentRecordContextChange += GridGroupingControl1_CurrentRecordContextChange; 
//Event Customization 
private void GridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) 
{ 
    int colIndex = this.gridGroupingControl1.TableControl.CurrentCell.ColIndex; 
    //To move the right cell when pressing Enter on AddNewRecordRow and restrict the new record being added when enter the value until last column 
    if (e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditCalled && e.Table.AddNewRecord.IsCurrent 
        && colIndex != this.gridGroupingControl1.TableControl.TableDescriptor.Columns.Count) 
    { 
        e.Cancel = true; 
        this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(this.gridGroupingControl1.TableControl.CurrentCell.RowIndex, colIndex + 1, GridSetCurrentCellOptions.SetFocus); 
    } 
    if (e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditCalled && e.Table.AddNewRecord.IsCurrent 
        && colIndex == this.gridGroupingControl1.TableControl.TableDescriptor.Columns.Count) 
    { 
        //Validate the current record values and defines whether it can be added or not. 
        if ((int)e.Record.GetRecord().GetValue("CategoryID") > 100) 
        { 
            e.Cancel = true; 
        } 
    } 
} 
 
 

Sample link: http://www.syncfusion.com/downloads/support/forum/130099/ze/DataGrid_20151195234678  

 
Please let us know if we misunderstood anything. 

Regards, 
Arulpriya 


Michael K
Replied On April 24, 2017 10:55 AM

Dear Arulpriya :

Thanks for your coding and I will try on it.

Howvever, when I try to write a project to about Control GridDataBoundGrid, I find the below problems, Can you help ?
1. When I set EnableAddNew = false
   when I input the value at the last column and last row of GridDataBoundGrid and press enter or tab key, it will not trigger the event CurrentCellEditingComplete. For other column is work. 
2. I make a control to inherit GridDataBoundGrid, and try override the function CurrentCellEditingComplete, it can't. What I want it, I would like to write the common function on after column[x] value edit. How can do it ?

Thanks for your help

Michael

Arulpriya Ramalingam [Syncfusion]
Replied On April 25, 2017 04:52 AM

Hi Michael, 

Thanks for your update. 

By default, the CurrentCellEditingComplete event will be triggered when the CurrentCell is moved to next cell and the current cell is moved to right cell on Enter key pressed. If the Enter key is pressed on last column, there is no right cell to move, so the current cell will be remain in same. Your scenario can be achieved by some workaround using CurrentCellKeyDown event. In that event, the current cell is moved to 1st column of next row if the current cell is in last column by using GridCurrentCell.MoveTo() method. Please make use of below code and sample, 

Code snippet 
//Event triggering 
this.gridDataBoundGrid1.CurrentCellKeyDown += GridDataBoundGrid1_CurrentCellKeyDown1; 

//Event customization 
private void GridDataBoundGrid1_CurrentCellKeyDown1(object sender, KeyEventArgs e) 
{ 
    if(e.KeyCode==Keys.Enter) 
    { 
        GridCurrentCell currentCell = gridDataBoundGrid1.CurrentCell; 
        if (currentCell.ColIndex==this.gridDataBoundGrid1.GridBoundColumns.Count) 
        { 
            if (currentCell.RowIndex == this.gridDataBoundGrid1.Binder.RecordCount) 
                //To move the first cell if the current cell is last column of the last row 
                currentCell.MoveTo(1, 1); 
            else 
                //To move the first column of next row 
                currentCell.MoveTo(currentCell.RowIndex + 1, 1); 
            e.Handled = true; 
        } 
         
    } 
} 
//Event triggering 
this.gridDataBoundGrid1.CurrentCellEditingComplete += GridDataBoundGrid1_CurrentCellEditingComplete; 
 
//Event customization 
private void GridDataBoundGrid1_CurrentCellEditingComplete(object sender, EventArgs e) 
{ 
   //Code to perform  
} 


Regards, 
Arulpriya 


Michael K
Replied On April 25, 2017 10:35 AM

Dear Arulpriya :

Thanks for your advice, and your advice is usefull for solve question 1
for question 2
How can I handle on override function of CurrentCellEditingComplete  in GridDataBoundGrid.
It seem the control not allow me to override, but I need to write common function on after column edit.

Thank you

Michael

Arulpriya Ramalingam [Syncfusion]
Replied On April 26, 2017 02:26 AM

Hi Michael, 

Thanks for your update. 

The CurrentCellEditingComplete event can be overridden by OnCurrentCellEditingComplete method of the custom DataBoundGrid control which implements the GridDataBoundGrid class. This OnCurrentCellEditingComplete  method will be triggered when the current cell editing is completed. Please make use of below code and sample, 

Code snippet 
 
//Custom DataBoundGrid class 
public class CustomDataBoundGrid: GridDataBoundGrid 
{ 
    protected override void OnCurrentCellEditingComplete(EventArgs e) 
    { 
        base.OnCurrentCellEditingComplete(e); 
        /// 
        ///Code to perform 
        /// 
    } 
} 
//Event Triggering 
this.customGrid.CurrentCellEditingComplete += CustomGrid_CurrentCellEditingComplete; 
 
//Event customization 
private void CustomGrid_CurrentCellEditingComplete(object sender, EventArgs e) 
{ 
    //Code to perform 
} 


Regards, 
Arulpriya

Michael K
Replied On April 27, 2017 11:25 PM

Hi :

I get it , thanks a lot

:)

Cheer

Arulpriya Ramalingam [Syncfusion]
Replied On April 27, 2017 11:59 PM

Hi Michael,   

We are glad to hear that the provided solution is resolved your scenario.   

Please let us know if you need any further assistance.    
   
Regards,   
Arulpriya 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;