|
public class CustomCell : GridCell
{
SfMaskedEdit maskedEdit;
public CustomCell(Context context) : base(context)
{
maskedEdit = new SfMaskedEdit(context);
maskedEdit.Mask = "00/00/0000";
maskedEdit.Value = @"14/11/2014";
maskedEdit.Focusable = true;
this.maskedEdit.FocusChange += MaskedEdit_FocusChange1;
this.AddView(maskedEdit);
}
private void MaskedEdit_FocusChange1(object sender, FocusChangeEventArgs e)
{
if (e.HasFocus)
{
//BeginEdit operation
}
else
{
//EndEdit opertation
}
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
}
} |
Hi Bharath,
We have checked with SfMaskedEdit control and we saw that when tap on gridcell the focus goes to SfMaskedEdit control because SfMaskedEdit is an editable control. So, only the begin edit and end edit event’s are not triggered. However, you can write your begin edit operation and end edit operation on FocusChange event of the SfMaskedEdit control. Please refer to the below code snippet and attached sample.
Code snippet :
public class CustomCell : GridCell{SfMaskedEdit maskedEdit;public CustomCell(Context context) : base(context){maskedEdit = new SfMaskedEdit(context);maskedEdit.Mask = "00/00/0000";maskedEdit.Value = @"14/11/2014";maskedEdit.Focusable = true;this.maskedEdit.FocusChange += MaskedEdit_FocusChange1;this.AddView(maskedEdit);}private void MaskedEdit_FocusChange1(object sender, FocusChangeEventArgs e){if (e.HasFocus){//BeginEdit operation}else{//EndEdit opertation}}protected override void OnDraw(Canvas canvas){base.OnDraw(canvas);}}
Sample link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGridAndroid430297888896481376.zip
Regards,
Karthik Raja
|
public class ViewModel : INotifyPropertyChanged
{
public ViewModel()
{
SetRowsToGenerate(6);
}
private DataTable dataTable;
public DataTable DataTable
{
get { return dataTable; }
set
{
this.dataTable = value;
RaisePropertyChanged("DataTable");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(String Name)
{
if (PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(Name));
}
} |
|
public class CustomCell : GridCell
{
SfMaskedEdit maskedEdit;
public CustomCell(Context context) : base(context)
{
maskedEdit = new SfMaskedEdit(context);
maskedEdit.Mask = @"00/00/0000";
maskedEdit.Focusable = true;
this.maskedEdit.FocusChange += MaskedEdit_FocusChange1;
this.AddView(maskedEdit);
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
if (maskedEdit.Value.ToString() == "")
{
//During initialization, Update the MaskedEdit value with the DataTable value
maskedEdit.Value = (DataColumn.CellValue.ToString());
}
else if (maskedEdit.Value.ToString() != "" && DataColumn.CellValue.ToString() != maskedEdit.Value.ToString())
{
//On Editing, Update the DataTable value with the MaskedEdit value
DataColumn.Renderer.DataGrid.View.GetItemProperties().
SetValue(DataColumn.RowData, maskedEdit.Value.ToString(), DataColumn.GridColumn.MappingName);
}
}
} |
|
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
LinearLayout layout = new LinearLayout(this);
layout.Orientation = Orientation.Vertical;
layout.SetBackgroundColor(Color.White);
viewModel = new ViewModel();
sfgrid = new SfDataGrid(this);
sfgrid.ItemsSource = viewModel.DataTable;
sfgrid.AutoGenerateColumns = false;
sfgrid.AllowEditing = true;
sfgrid.SelectionMode = SelectionMode.Single;
sfgrid.NavigationMode = NavigationMode.Cell;
sfgrid.RowHeight = 50;
var Column = new GridTextColumn();
Column.MappingName = "Name";
Column.HeaderText = "Caption";
Column.UserCellType = typeof(CustomCell);
Column.TextMargin = 2;
sfgrid.Columns.Add(Column);
sfgrid.CurrentCellBeginEdit += Sfgrid_CurrentCellBeginEdit;
sfgrid.CurrentCellEndEdit += Sfgrid_CurrentCellEndEdit;
layout.AddView(sfgrid);
SetContentView(layout);
} |