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.

GridTemplateColumn stealing focus from SfDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

127496 Nov 18,2016 02:03 PM Nov 22,2016 01:33 PM WPF 3
loading
Tags: SfDataGrid
Karmen
Asked On November 18, 2016 02:03 PM

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

Srinivasan Vasu [Syncfusion]
Replied On November 21, 2016 07:02 AM

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 
 


Karmen
Replied On November 21, 2016 02:29 PM

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

Srinivasan Vasu [Syncfusion]
Replied On November 22, 2016 01:33 PM

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 
 


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.

;