Skip to content

Instantly share code, notes, and snippets.

@pmalicki11
Last active September 12, 2023 11:12
Show Gist options
  • Save pmalicki11/f9850b499c03c69f1e95137719871199 to your computer and use it in GitHub Desktop.
Save pmalicki11/f9850b499c03c69f1e95137719871199 to your computer and use it in GitHub Desktop.
Adding Custom column to DataView
// UI Customization side
// Adding a column to the view and setting some props
private void UpdateWhereUsedView()
{
EpiDataView edvPartWhereUsed = (EpiDataView)(oTrans.EpiDataViews["PartWhereUsed"]);
if (!edvPartWhereUsed.dataView.Table.Columns.Contains("ForecastYearQty"))
{
edvPartWhereUsed.dataView.Table.Columns.Add(new DataColumn("ForecastYearQty", typeof(decimal)));
edvPartWhereUsed.dataView.Table.Columns["ForecastYearQty"].ExtendedProperties["ReadOnly"] = true;
edvPartWhereUsed.dataView.Table.Columns["ForecastYearQty"].ExtendedProperties["Caption"] = "Yr Forecast";
}
}
// BPM side
// Adding column name with the same name and populate it
if (result.PartWhereUsed.ExtendedColumns.All(column => column.ColumnName != "ForecastYearQty"))
{
var list = new List<ExtendedColumn>(result.PartWhereUsed.ExtendedColumns);
list.Add(new ExtendedColumn("ForecastYearQty", typeof(decimal)));
typeof(IceTable<Erp.Tablesets.PartWhereUsedRow>)
.GetField("extendedColumns", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
.SetValue(null, list.ToArray(), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, null);
}
foreach (var row in result.PartWhereUsed)
{
var part = Db.Part.FirstOrDefault(r => r.Company == row.Company && r.PartNum == row.PartNum);
if (part != null)
{
row["ForecastYearQty"] = part.ForecastYearQty_c;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment