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. Image for the cookie policy date

GridTemplateColumn stealing focus from SfDataGrid

Hello!

I am having problems with the GridTemplateColumn stealing focus from SfDataGrid and therefore calling OnRowValidated event prematurely. All this results in adding the new row too soon.

I would be glad to receive any of your thoughts on how to resolve this problem.

Regards,

Karmen Gostiša

3 Replies

SV Srinivasan Vasu Syncfusion Team November 21, 2016 12:02 PM UTC

Hi Karmen, 
 
Thanks for contacting Syncfusion support. 
 
We cannot understand your query clearly and we have prepared a sample with GridTemplateColumn in SfDataGrid. You can set focus to the GridTemplateColumn using FocusManagerHelper.FocusedElement as True. 
 
 
Please refer the below UG Link. 
 
 
Could you please modified the sample along with replication procedure and share more details about your requirement? It will be helpful for us to provide better solution. 
 
 
Regards, 
Srinivasan 
 



KA Karmen November 21, 2016 07:29 PM UTC

Hi!

This is almost what I need. The only problem I have now is that the event OnRowValidating is not called after I finish editing the GridTemplateColumn or press Enter. 

I would like to achieve the same functionality as the DateTime and other provided columns but with Autocomplete (SfTextBoxExt).

I would be happy to read any thoughts on this.

Regards,

Karmen Gostiša


SV Srinivasan Vasu Syncfusion Team November 22, 2016 06:33 PM UTC

Hi Karmen, 
 
 
We checked your query and SfDdataGrid do not have CurrentCellValidating support for GridTemplateColumn. We have prepared a workaround for your requirement.   
In this sample, we have used RowValidatingEvent and CurrentCellActivatingEvent to check the cell value is valid or not in GridTemplateColumn.   
  
Code Example:  
  
          
  private void DataGrid_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs args)  
        {  
            if (args.PreviousRowColumnIndex.RowIndex <= 0)  
                return;  
            var record = this.dataGrid.GetRecordAtRowIndex(args.PreviousRowColumnIndex.RowIndex);  
            var column =this.dataGrid.Columns[this.dataGrid.ResolveToGridVisibleColumnIndex(args.PreviousRowColumnIndex.ColumnIndex)];  
            if (column.MappingName.Equals("Salary"))  
            {  
                var cellValue = this.dataGrid.View.GetPropertyAccessProvider().GetValue(record, column.MappingName);  
                if (cellValue != null && int.Parse(cellValue.ToString()) <= 0)  
                {  
                    args.Cancel = true;  
                    MessageBox.Show("Salary should not be negative");  
                    this.dataGrid.SelectionController.CurrentCellManager.BeginEdit();  
                }  
            }  
        }  
  
        private void DataGrid_RowValidating(object sender, RowValidatingEventArgs args)  
        {  
            if (args.RowIndex <= 0)  
                return;  
            var record = this.dataGrid.GetRecordAtRowIndex(args.RowIndex);  
            var column = this.dataGrid.Columns[this.dataGrid.ResolveToGridVisibleColumnIndex(4)];  
            if (column.MappingName.Equals("Salary"))  
            {  
                var cellValue = this.dataGrid.View.GetPropertyAccessProvider().GetValue(record, column.MappingName);  
                if (cellValue != null && int.Parse(cellValue.ToString()) <= 0)  
                {  
                    args.IsValid = false;  
                    MessageBox.Show("Salary should not be negative");  
                    this.dataGrid.SelectionController.CurrentCellManager.BeginEdit();  
                }  
            }  
  
        }  
  
  
Please find the sample from the below location.  
  
 
 
 
Regards, 
Srinivasan 
 


Loader.
Up arrow icon