[C#]
public class CustomCell : GridCell
{
LinearLayout layout;
RadioButton radioButton;
RadioButton radioButton1;
public CustomCell(Context context) : base(context)
{
layout = new LinearLayout(this.Context);
radioButton = new RadioButton(this.Context);
radioButton1 = new RadioButton(this.Context);
layout.AddView(radioButton);
layout.AddView(radioButton1);
this.AddView(layout);
}
protected override void UnLoad()
{
if (this.Parent != null)
(this.Parent as VirtualizingCellsControl).RemoveView(this);
}
protected override void OnLayout(bool change, int l, int t, int r, int b)
{
this.layout.Layout(0, 0, this.Width, this.Height);
}
protected override void OnMeasure(int widthMeasureSpec, intheightMeasureSpec)
{
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
this.layout.Measure(widthMeasureSpec, heightMeasureSpec);
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
this.radioButton.Text = "Yes";
this.radioButton1.Text = "No";
}
} |
The provided example does not work with a RadioGroup, which is necessary to manage the behavior of related RadioButtons. Can you provide an updated example?
Hi Richard,
We would like to let you know that we have checked loading RadioGroup inside SfDataGrid Template column, it works fine on our end. Please refer the below code snippets of loading RadioGroup as a custom cell.
Code Snippets:
protected override void OnCreate (Bundle bundle) { base.OnCreate(bundle); Window.AddFlags(WindowManagerFlags.Fullscreen); … GridTextColumn customerIdColumn = new GridTextColumn(); customerIdColumn.UserCellType = typeof(CustomCell); customerIdColumn.MappingName = "Dummy"; customerIdColumn.HeaderText = "RadioColumn"; dataGrid.Columns.Add(new GridTextColumn() { MappingName = "OrderID" }); dataGrid.Columns.Add(new GridTextColumn() { MappingName = "CustomerID" }); dataGrid.Columns.Add(customerIdColumn); dataGrid.SetBackgroundColor(Color.Purple); SetContentView(dataGrid); }
public class CustomCell : GridCell { LinearLayout layout; RadioGroup radioGroup; RadioButton radioButton; RadioButton radioButton1;
public CustomCell(Context context) : base(context) { layout = new LinearLayout(this.Context); radioGroup = new RadioGroup(this.Context); radioButton = new RadioButton(this.Context); radioButton1 = new RadioButton(this.Context); radioGroup.AddView(radioButton); radioGroup.AddView(radioButton1); layout.AddView(radioGroup); this.AddView(layout); }
protected override void UnLoad() { if (this.Parent != null) (this.Parent as VirtualizingCellsControl).RemoveView(this); }
protected override void OnLayout(bool change, int l, int t, int r, int b) { this.layout.Layout(0, 0, this.Width, this.Height); }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); this.layout.Measure(widthMeasureSpec, heightMeasureSpec); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); this.radioButton.Text = "Yes"; this.radioButton1.Text = "No"; } } |
We have attached a runnable sample with image illustration for your reference. You can customize the sample as per wish. Please let us know if you need any further assistance.
Regards,
Suja