//Get DataRow
var row = dataGrid.GetRowGenerator().Items; |
//Get the index of particular DataRow
var row = dataGrid.GetRowGenerator().Items.IndexOf(item); // where item is a DataRow |
foreach(var item in dataGrid.View.Records)
{
//Get the row data of the rows
var rowData = item.Data;
} |
foreach (var item in dataGrid.View.Records)
{
//Get the row data of the rows
var rowData = item.Data;
foreach (var column in dataGrid.Columns)
{
//Get the cell value for each column
var cellValue = dataGrid.GetCellValue(rowData, column.MappingName);
}
} |
Style style = new Style(typeof(GridCell));
style.Setters.Add(new Setter() { Property = GridCell.BackgroundColorProperty, Value = Color.Blue});
foreach (var column in sfGrid.Columns)
{
if (column.MappingName == "CustomerID")
column.CellStyle = style;
} |
//Main Page
Style style = new Style(typeof(GridCell));
style.Setters.Add(new Setter() { Property = GridCell.BackgroundColorProperty, Value = new Binding() { Path = "OrderID", Converter = new Converter() } });
foreach (var column in sfGrid.Columns)
{
if (column.MappingName == "OrderID")
column.CellStyle = style;
}
//Converter class
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var data = (int)value;
if (data == 10004)
return Color.Blue; // You can achieve your requirement here.(applying styles for particular cell based on the cell value)
return Color.Default;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
} |
sfGrid.GridViewCreated += SfGrid_GridViewCreated;
private void SfGrid_GridViewCreated(object sender, GridViewCreatedEventArgs e)
{
SfDataGrid dg = (SfDataGrid)sender;
//get the max items and min items from Grid for each column
List<int[]> maxList = GetColumnValue(dg, true);
List<int[]> lowList = GetColumnValue(dg, false);
//highlight the cells
HighLightCells(dg, lowList, true);
HighLightCells(dg, maxList, false);
} |
public class CustomCellStyleSelector : StyleSelector
{
public override Style SelectStyle(object item, System.Windows.DependencyObject container)
{
var gridCell = container as GridCell;
var mappingName = gridCell.ColumnBase.GridColumn.MappingName;
var record = gridCell.DataContext;
var cellValue = record.GetType().GetProperty(mappingName).GetValue(record);
if (mappingName.Equals("OrderID"))
{
if (Convert.ToInt16(cellValue) <= 1005)
return App.Current.Resources["cellStyle1"] as Style;
else
return App.Current.Resources["cellStyle2"] as Style;
}
return base.SelectStyle(item, container);
}
}
public override void LayoutSubviews ()
{
label.Frame =new CGRect(35,0,this.Frame.Width,this.Frame.Height) ;
label.Text =DataColumn.FormattedCellvalue;
if (label.Text == "Red")
label.TextColor = UIColor.Red;
else if (label.Text == "Green")
label.TextColor = UIColor.Green;
else if (label.Text == "Yellow")
label.TextColor = UIColor.Yellow;
else if (label.Text == "Orange")
label.TextColor = UIColor.Orange;
else
label.TextColor = UIColor.White;
base.LayoutSubviews ();
} |