- Home
- Forum
- Xamarin.Android
- Set strikeout for row in datagrid
Set strikeout for row in datagrid
Hi, is it possible to set the font in a specific row programatically to use a strikeout (example) in the sfdatagrid for Android?
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
KK
Karthikraja Kalaimani
Syncfusion Team
October 22, 2020 10:25 AM UTC
Hi Phunction,
We can achieve your requirement by writing Custom GridCell for the GridColumn. Since the Custom GridCell can accept any type of view. So, load the TextView in custom GridCell and apply the strikeout font to textview on OnDraw method of the GridCell. Please refer to the below code snippet and attached sample.
Code snippet :
We can achieve your requirement by writing Custom GridCell for the GridColumn. Since the Custom GridCell can accept any type of view. So, load the TextView in custom GridCell and apply the strikeout font to textview on OnDraw method of the GridCell. Please refer to the below code snippet and attached sample.
Code snippet :
|
……..
GridNumericColumn orderIdColumn = new GridNumericColumn(); orderIdColumn.MappingName = "OrderID";
orderIdColumn.UserCellType = typeof(CustomCell);
GridNumericColumn employeeIdColumn = new GridNumericColumn();
employeeIdColumn.MappingName = "EmployeeID";
employeeIdColumn.UserCellType = typeof(CustomCell);
GridTextColumn lastNameColumn = new GridTextColumn();
lastNameColumn.MappingName = "LastName";
lastNameColumn.HeaderText = "LastName";
lastNameColumn.UserCellType = typeof(CustomCell);
_dataGrid.Columns.Add(lastNameColumn);
_dataGrid.Columns.Add(orderIdColumn);
_dataGrid.Columns.Add(employeeIdColumn);
………… public class CustomCell : GridCell {
TextView textView;
public CustomCell(Context context) : base(context)
{
textView = new TextView(this.Context);
textView.TextAlignment = TextAlignment.Center;
this.AddView(textView);
}
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.textView.Layout(0, 0, this.Width, this.Height);
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
if ((DataColumn.RowData as OrderInfo).OrderID == 10001)
{
var font = Typeface.CreateFromAsset(Helpers.aqssetManager, "StrikeOut.otf");
textView.Typeface = font;
}
else if (textView.Typeface != null)
{
textView.Typeface = null;
}
this.textView.Text = DataColumn.CellValue.ToString();
}
} |
Sample link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SupportAndroid886373243.zip
Regards,
Karthik Raja
Marked as answer
PH
Phunction
October 22, 2020 03:45 PM UTC
My columns are being created through the bound datatable, ie:
dataTable = new DataTable();
dataTable.Columns.Add("Name");
dataTable.Columns.Add("ID");
Is there still a way to do it when adding columns this way instead of directly to the grid?
Can I simply do this after creating the datatable and binding it:
lastNameColumn.UserCellType = typeof(CustomCell);
or does this part have to be done before adding the column?
KK
Karthikraja Kalaimani
Syncfusion Team
October 23, 2020 11:01 AM UTC
Hi Phunction,
Yes, you have to set UserCellType to the column once the it is created. You can also set UserCellType to all the columns on AutoGenerationgColumn of the SfDataGrid. Please refer the below code snippet for that.
Code snippet :
Yes, you have to set UserCellType to the column once the it is created. You can also set UserCellType to all the columns on AutoGenerationgColumn of the SfDataGrid. Please refer the below code snippet for that.
Code snippet :
|
private void _dataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnEventArgs e)
{
e.Column.UserCellType = typeof(CustomCell);
} |
Regards,
Karthik Raja
PH
Phunction
October 23, 2020 05:31 PM UTC
Thanks, I almost have it but I just need to change this part:
if ((DataColumn.RowData as OrderInfo).OrderID == 10001)
I am using a datatable, not a view model, how can I check the value in a certain row,col?
For example, a value in column 10 will determine if all the cells in the current row should have a strike through.
KK
Karthikraja Kalaimani
Syncfusion Team
October 26, 2020 11:48 AM UTC
Hi Phunction,
You can check the row value by using the ItemArray property of DataRowView. Please refer to the below code snippet.
Code snippet :
Code snippet :
|
if ((DataColumn.RowData as System.Data.DataRowView).Row.ItemArray[1].ToString() == "10001")
{
var font = Typeface.CreateFromAsset(Helpers.aqssetManager, "StrikeOut.otf");
textView.Typeface = font;
} |
Regards,
Karthik Raja
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
- Marked answer
-
PH Phunction
- Oct 21, 2020 11:59 PM UTC
- Oct 26, 2020 11:48 AM UTC