|
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
dataGrid = FindViewById<SfDataGrid>(Resource.Id.sfDataGrid);
orderI = new ViewModel();
dataGrid.ColumnSizer = ColumnSizer.None;
dataGrid.AutoGenerateColumns = false;
dataGrid.RowHeight = 100;
GridTextColumn employeeId = new GridTextColumn();
employeeId.MappingName = "ID";
dataGrid.Columns.Add(employeeId);
GridTextColumn customerIdColumn = new GridTextColumn();
customerIdColumn.UserCellType = typeof(CustomCell);
customerIdColumn.MappingName = "Percentage";
customerIdColumn.HeaderText = "Percentage";
dataGrid.Columns.Add(customerIdColumn);
dataGrid.ItemsSource = orderI.Info;
}
public class CustomCell : GridCell
{
LinearLayout layout;
RadioButton radioButton;
public CustomCell(Context context) : base(context)
{
layout = new LinearLayout(this.Context);
radioButton = new RadioButton(this.Context);
radioButton.TextAlignment = TextAlignment.Center;
layout.AddView(radioButton);
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);
}
}
|
|
public class CustomCell : GridCell
{
LinearLayout layout;
public CustomCell(Context context) : base(context)
{
layout = new LinearLayout(this.Context);
LayoutInflater inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
View view = inflater.Inflate(Resource.Layout.CustomLayout, null, false);
layout.AddView(view);
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);
}
}
|
|
public class MainActivity : Activity
{
private SfDataGrid dataGrid;
private ViewModel orderI;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
dataGrid = FindViewById<SfDataGrid>(Resource.Id.sfDataGrid);
orderI = new ViewModel();
dataGrid.ColumnSizer = ColumnSizer.None;
dataGrid.AutoGenerateColumns = false;
dataGrid.RowHeight = 100;
GridTextColumn employeeId = new GridTextColumn();
employeeId.MappingName = "ID";
dataGrid.Columns.Add(employeeId);
GridTextColumn customerIdColumn = new GridTextColumn();
customerIdColumn.HeaderTemplate = GenerateView("Percentage");
customerIdColumn.MappingName = "Percentage";
customerIdColumn.HeaderText = "Percentage";
dataGrid.Columns.Add(customerIdColumn);
dataGrid.ItemsSource = orderI.Info;
}
private View GenerateView(string text)
{
LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View view = inflater.Inflate(Resource.Layout.CustomLayout, null, false);
(view as TextView).SetText(text, TextView.BufferType.Normal);
return view;
}
}
|