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
close icon

How to add two radio buttons (Yes and No) in sfDataGrid column

Hi,

I want to add two radio buttons (Yes and No) inside template column of the sfDataGrid. Could you please share the example for this?

I want this kind of layout inside sfDataGrid column:



7 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team February 27, 2019 11:09 AM UTC

Hi Deepa, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your requirement of “Showing two radio buttons inside the DataGrid column” in Xamarin.Forms can be achieved using CellTemplate of GridTemplateColumn. You can set the desired DataTemplate in the GridTemplateColumn based on your requirement. 
 
We have prepared sample based on your requirement, please find the sample by the following link. 
 
Sample link: GridEditSample 
 
In the sample, we have added columns and in the last column we have handled two Switch in the layout. 
 
We hope this helps. Please let us know, if you need any further assistance. 
 
Regards,
Subburaj Pandian V  
 



DE Deepa March 1, 2019 09:48 AM UTC

The solution you provided is using xamarin.forms.
I want the solution for native xamarin android.

Please provide me the sample in native xamarin android


SP Subburaj Pandian Veluchamy Syncfusion Team March 4, 2019 09:34 AM UTC

Hi Deepa, 
 
Sorry for the inconvenience caused. 
 
We have prepared sample based on your requirement “Showing radio button inside the DataGrid column” in Xamarin.Android. Please find the sample by the following link.

Sample link: GridTemplateColumn_Droid 
 
In the sample, we have loaded Radio Button inside the DataGrid column by using UserCellType property of GridTextColumn. Using this you can pass the required view to the custom column of Grid. 
 
You can refer the same by the following UG documentation, 
 
 
We hope this helps. Please let us know, if you have any concern. 
 
Regards,
Subburaj Pandian V  



DE Deepa March 4, 2019 09:49 AM UTC

I already tried this code. But this adds only one radio button to the column.
I want to add two radio buttons 'Yes', 'No' to the column.

Whenever i try to add second radio button, it gives me empty column.

I have waiting for 3 days to add this functionality. Please provide the sample as soon as possible. 


SP Subburaj Pandian Veluchamy Syncfusion Team March 5, 2019 09:05 AM UTC

 
Hi Deepa, 
  
Thank you for the update. 
  
We have prepared the sample based on your requirement “Load two radio button in template column” and please refer the following code snippet for Custom Cell class changes. 
  
[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"; 
    } 
} 
  
We have attached the sample in following location. 
  
 
Please let us know, if this helpful. 
 
Regards,
Subburaj Pandian V 
 



RP Richard Popovich October 13, 2022 02:05 PM UTC

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?



SV Suja Venkatesan Syncfusion Team October 14, 2022 11:55 AM UTC

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


Attachment: T142932_72d8a7d1.zip

Loader.
Live Chat Icon For mobile
Up arrow icon