Regarding GridDateTimeColumn Column Type

I has place GridDateTimeColumn in SFDataGrid and require solution for below mentioned problems
[1] I want GridDateTimeColumn in edit mode on page load & Add new row event
[2] When editing column it should  in dd-MM-yyyy format
[3] After editing date when i press tab key Date is not saved it is reverted to default date, how to save it on tab key
[4] When i use CommitNewRow function on Row Initiating Event it is adding an extra row to SFDataGrid.
[5] I need to skip 2 columns from tab event.(i.e. When is press tab key on column 1, cursor should be moved to column 4)



6 Replies

AA Arulraj A Syncfusion Team August 29, 2018 09:50 AM UTC

Hi Avinash, 

Thanks for contacting Syncfusion Support. 

Query 
Solution 
I want GridDateTimeColumn in edit mode on page load & Add new row event 
This can be achieved by moving the current cell to the required cell using SfDataGrid.MoveToCurrentCell method within the Form.Shown event and the SfDataGrid.AddNewRowInitiating event. Please refer to the following code example. 

this.Shown += Form1_Shown; 
 
void Form1_Shown(object sender, EventArgs e) 
{ 
    sfDataGrid.TableControl.Update(); 
    sfDataGrid.MoveToCurrentCell(new RowColumnIndex(1, 3)); 
    sfDataGrid.CurrentCell.BeginEdit(); 
} 
 
this.sfDataGrid.AddNewRowInitiating += sfDataGrid_AddNewRowInitiating; 
 
void sfDataGrid_AddNewRowInitiating(object sender, Syncfusion.WinForms.DataGrid.Events.AddNewRowInitiatingEventArgs e) 
{ 
       this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(1, 3)); 
} 
 
When editing column it should  in dd-MM-yyyy format 
To change the format for the DateTimeColumn in editing, set value for the GridDateTimeColumn.Pattern property as DateTimePattern.Custom and  set the desired format using Format Property. Please refer to the following code example. 

Code Example: 
 
(this.sfDataGrid.Columns["OrderDate"] as GridDateTimeColumn).Pattern = Syncfusion.WinForms.Input.Enums.DateTimePattern.Custom; 
(this.sfDataGrid.Columns["OrderDate"] as GridDateTimeColumn).Format = "dd/MM/yyyy"; 
 
After editing date when I press tab key Date is not saved it is reverted to default date, how to save it on tab key 
We can able to reproduce the reported scenario in our end. We will fix this issue in our 2018 volume 3 release, which is expected to be rolled out in the end of September, 2018. 
When I use CommitNewRow function on Row Initiating Event it is adding an extra row to SFDataGrid. 
We have analyzed this reported scenario. By default, when the focus is moved from AddNewRow to any other row, the AddNewRow value will be committed to the view. This is the expected behavior. Currently we don’t have support to cancel adding new row within the AddNewRowInitiating event. We have logged this requirement as a feature request in our database and we have planned to implement this in our 2018 Volume 3 release, which is expected to be rolled out in the end of September, 2018. 
I need to skip 2 columns from tab event.(i.e. When is press tab key on column 1, cursor should be moved to column 4) 
SfDataGrid doesn’t have direct support to skip the tab key navigation for any specific columns. But this can be achieved by moving the current cell to the required column when pressing tab key on the current cell by handling the SfDataGrid.TableControl.KeyDown event. Please refer to the below code example. 

Code Example :  

this.sfDataGrid.TableControl.KeyDown += TableControl_KeyDown; 
 
void TableControl_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (this.sfDataGrid.CurrentCell.ColumnIndex == 1 && e.KeyCode == Keys.Tab) 
    { 
        e.Handled = true; 
        this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex, 4)); 
    } 
} 
 
 

Please refer to the sample from the following link. 


Regards,   
Arulraj A   



AV Avinash August 30, 2018 12:23 PM UTC

Is there any to handle shift+tab event(i.e when i press shift+tab it is moving to previous cell but i want to move it cell in need on shift+tab event)


AA Arulraj A Syncfusion Team August 31, 2018 04:42 AM UTC

Hi Avinash, 

Thanks for your update. 

You can skip both tab key and shift + tab key navigation for specific columns by using SfDataGrid.MoveToCurrentCell method within the SfDataGrid.TableCotrol.MouseDown event. Please refer to the following code example and sample from the given location. 

Code Example :  

this.sfDataGrid.TableControl.KeyDown += TableControl_KeyDown; 
 
void TableControl_KeyDown(object sender, KeyEventArgs e) 
{ 
    //To skip tab key navigation for two columns. 
    if (this.sfDataGrid.CurrentCell.ColumnIndex == 1 && e.KeyCode == Keys.Tab && !e.Shift) 
    { 
        e.Handled = true; 
        this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex, 4)); 
    } 
    //To skip shift + tab key navigation for two columns. 
    else if (this.sfDataGrid.CurrentCell.ColumnIndex == 4 && e.KeyCode == Keys.Tab && e.Shift) 
    { 
        e.Handled = true; 
        this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex, 1)); 
    } 
} 

 
Regards, 
Arulraj A 



AV Avinash August 31, 2018 05:40 AM UTC

  When Using sfDataGrid.CurrentCell.BeginEdit() Or Pressing Tab Key It is No Showing cursor , How can i achieve this requirement ?
  Need This in AddNewRow & Normal Row Both


AA Arulraj A Syncfusion Team August 31, 2018 12:33 PM UTC

Hi Avinash, 

Thanks for your update. 

SfDataGrid.CurrentCell.BeginEdit() method will display edit cursor by default. But only after pressing tab key the current cell will be moved to the next cell until then editing will not be started. Even though this can be achieved by handling the SfDataGrid.TableControl.KeyDown event. Please refer to the below code example and sample from the given location. 

Code Example: 

this.sfDataGrid.TableControl.KeyDown += TableControl_KeyDown; 
 
void TableControl_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.KeyCode == Keys.Tab) 
    { 
        e.Handled = true; 
        this.sfDataGrid.CurrentCell.BeginEdit(); 
    } 
} 


Arulraj A 



AA Arulraj A Syncfusion Team September 18, 2018 10:15 AM UTC

 
We are glad to announce that our v16.3.0.17 beta release is rolled out, we have fixed the issue “Edited value is not committed in the GridDateTimeColumn before tab key navigation” and provided Support to “Cancel adding new row within the AddNewRowInitiating event”and it is available for download under the following link.  
   
  
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
 
Regards, 
Arulraj A 


Loader.
Up arrow icon