Registered Event in CurrentCellBeginEdit not firing in Version >18.4.0.43

Hi,

we have a SFDataGrid which contains a GridTextColumn and a GridNumericColumn.

On entering a row with CurrentCellBeginEdit we have some validations which only have to made if the current cell is on focus.

In the forum we have found a workaround which works fine. When we update our Syncfusion Version on greater than 18.4.0.43 it not jumps in the events which are called in the CurrentCellBeginEdit event (e.g. in the code below row (content as Entry).Completed += Charge_Completed;)


private async void dgChargen_CurrentCellBeginEdit(object sender, GridCurrentCellBeginEditEventArgs args)

{

try

{

var _charge = (Charge)dgChargen.SelectedItem;


if (_charge.Gesperrt)

args.Cancel = true;


// Workaround: Unter Umständen kann es vorkommen, das trotz SelectioMode=Single mehrere Zeilen selektiert werden, das wird in folgendem verhindert

var _selectedItem = dgChargen.SelectedItem;

dgChargen.SelectedItem = null;

dgChargen.SelectedItem = _selectedItem;


await Task.Delay(100);


// Aktuelle Zeile laden

var row = dgChargen.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == args.RowColumnIndex.RowIndex);


// Aktuelle Zelle laden

var column = (row.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "VisibleColumns").GetValue(row) as List).FirstOrDefault(x => x.ColumnIndex == args.RowColumnIndex.ColumnIndex);


// Content der aktuellen Zelle

var content = ((column as IElement).Element as ContentView).Content;



if (content is Entry && viewModel.Erfassungsart == DialogErfassungsModus.Erfassung)

{

// Chargeneingabe

(content as Entry).Completed += Charge_Completed;

_entryCompletedChargeHinzugefuegt = true;

}

else if (content is SfNumericTextBoxExt)

{

// Gewählt-Feld

// Artikel besitzt Chargen- und Seriennummernpflicht: Seriennummernerfassung

if (viewModel.FaBelegPosition.Nachweispflicht == 3 && dgChargen.SelectedIndex >= 1)

{

var _seriennrerfassung = await ErfasseSeriennummern(viewModel.Chargen[dgChargen.SelectedIndex - 1]);

if (_seriennrerfassung)

Gewaehlt_Completed(sender, new EventArgs());

}

else

{

// Gewaehlt Eingabe

(content as SfNumericTextBoxExt).Completed += Gewaehlt_Completed;

_entryNumericCompletedHinzugefuegt = true;

}

}


await Task.Delay(50);


// Summenspalte aktualisieren

viewModel.RefreshChargenSpalte();

}

catch (Exception ex)

{

await Application.Current.MainPage.DisplayAlert(nameof(dgChargen_CurrentCellBeginEdit), ex.Message, "OK");

}

}



Regards

Maria


3 Replies 1 reply marked as answer

KK Karthikraja Kalaimani Syncfusion Team July 27, 2021 10:50 AM UTC

Hi Maria, 

Thank you for contacting Syncfusion support.

We have prepared a workaround to trigger the completed event of NumericTextColumn and TextColumn. Please refer to the below code snippets. 

Code snippets : 
...  
            this.dataGrid.CellRenderers.Remove("TextView");
            this.dataGrid.CellRenderers.Add("TextView", new CustomTextViewRenderer());
            this.dataGrid.CellRenderers.Remove("Numeric");
            this.dataGrid.CellRenderers.Add("Numeric", new CustomNumericRenderer());
.....

        private async void dataGrid_CurrentCellBeginEdit(object sender, GridCurrentCellBeginEditEventArgs e)
        {

            await Task.Delay(100);
            var row = dataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == e.RowColumnIndex.RowIndex);


            // Aktuelle Zelle laden

            var column = (List<DataColumnBase>)(row.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "VisibleColumns").GetValue(row));



            // Content der aktuellen Zelle

            var content = ((column[e.RowColumnIndex.ColumnIndex] as IElement).Element as ContentView).Content;

            if (content is Entry)

            {
                // Chargeneingabe
                (content as Entry).Completed += MainPage_Completed;
            }
            else if (content is SfNumericTextBoxExt)
            {
                (content as SfNumericTextBoxExt).Completed += MainPage_Completed1;
            }

        }

        private void MainPage_Completed1(object sender, EventArgs e)
        {
            this.dataGrid.EndEdit();
        }

        private void MainPage_Completed(object sender, EventArgs e)
        {
            this.dataGrid.EndEdit();
        }
.....

 public class CustomNumericRenderer : GridCellNumericRenderer
    {

        public CustomNumericRenderer()
        {

        }

        protected override SfNumericTextBoxExt OnCreateEditUIView()
        {
            var view = new CustomNumericTextBox();
            return view;
        }
    }

    public class CustomNumericTextBox : SfNumericTextBoxExt
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NumericTextBoxView"/> class.
        /// </summary>  
        public CustomNumericTextBox()
        {
        }
    }

    public class CustomTextViewRenderer : GridCellTextViewRenderer
    {

        public CustomTextViewRenderer()
        {

        }

        protected override SfEntry OnCreateEditUIView()
        {
            var view = new CustomEntry();
            return (view as SfEntry);
        }
    }



    public class CustomEntry : SfEntry
    {

        public CustomEntry()
        {
           
        }
    }

//Renderer Class

[assembly: ExportRenderer(typeof(CustomNumericTextBox), typeof(CustomNumericTextBoxRenderer))]
namespace DataGridDemo.Droid
{
   
    public class CustomNumericTextBoxRenderer : SfNumericTextBoxRenderer
    {
        public CustomNumericTextBoxRenderer()
        {
       
        }

        protected override void OnElementChanged(ElementChangedEventArgs<SfNumericTextBox> e)
        {
            base.OnElementChanged(e);
        }
    }

}


[assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomRenderer))]
namespace DataGridDemo.Droid
{
    public class CustomRenderer : EntryRenderer
    {
        internal SfEntry FormsElement
        {
            get { return (SfEntry)this.Element; }
        }

        /// <summary>
        /// Gets the GridCell.
        /// </summary>
        private GridCell GridCell
        {
            get { return this.Element.Parent != null ? this.Element.Parent as GridCell : null; }
        }

        public CustomRenderer()
        {
       
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (this.Control != null)
            {
                if (e.PropertyName == "IsFocused")
                {
                    if (this.Element.IsFocused)
                    {
                        if (!string.IsNullOrEmpty(this.Control.Text))
                        {
                            if (this.GridCell.DataColumn.Renderer.DataGrid.EditorSelectionBehavior == EditorSelectionBehavior.SelectAll)
                            {
                                this.Control.SetSelection(0, this.Control.Text.Length);
                            }
                            else if (this.GridCell.DataColumn.Renderer.DataGrid.FlowDirection == FlowDirection.RightToLeft)
                            {
                                this.Control.SetSelection(0);
                            }
                            else
                            {
                                this.Control.SetSelection(this.Control.Text.Length);
                            }
                        }

                        // Fix for XAMARIN-29234 Additional tap requires for to show the keyboard while editing with Xamarin.Forms version 3.2 and above.
                        if (!this.Control.IsInputMethodTarget)
                        {
                            InputMethodManager inputManager = (InputMethodManager)this.Context.GetSystemService(Context.InputMethodService);
                            if (inputManager != null)
                            {
                                inputManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
                            }

                            inputManager = null;
                        }
                    }
                }
            }

        }
    }
}


Sample link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGridSample1586044745.zip

Regards,
Karthik Raja



Marked as answer

AN Andy July 29, 2021 11:22 AM UTC

Hi,


thanks for your quick response. With the renderers it works again!


Now I have a follow-up-problem. If I add a row in the grid, the content of the GridTextColumn is empty after leave the cell. If I click in it again the text appears.


I've modified your example to show the problem but the project its too large to upload here (300MB). I've attached the mofified View/Codebehind and the ViewModel.



Attachment: AddRow_9c727e14.zip


KK Karthikraja Kalaimani Syncfusion Team July 30, 2021 05:28 AM UTC

Hi Maria, 

Thanks for the update. 
  
You had missed to hook the OnPropertyChanged method for underlying properties. Due to this, the edited text is not showing on grid text column while leaving the cell. You can resolve this by calling the OnPropertyChanged method for underlying properties. Please refer to the below code snippets.

 
Code snippets : 
public class Charge : NotifyObject 
    { 
        private string name; 
  
        private decimal menge; 
        public string Name 
        { 
            get 
            { 
                return name; 
            } 
            set 
            { 
                name = value; 
  
                OnPropertyChanged("Name"); 
                
            } 
        } 
        public decimal Menge 
        { 
            get 
            { 
                return menge; 
            } 
            set 
            { 
                menge = value; 
                OnPropertyChanged("Menge"); 
            } 
        } 
    } 


Regards,
Karthik Raja



Loader.
Up arrow icon