在 ax POS 形式的网格控件中添加一列并显示总计
Add a column and show total in grid control in ax POS form
我正在使用 Devexpress 自定义 AX POS
打开 POS >> 收银任务 >> 取货 >> 转入/转出
在这里,我需要在 gvInventory 中添加一个名为 colDifference 的新列,它显示 orderedQty-Received
的差异
我还需要在 gridView
底部显示 diffQty 总数
I need to add a new column in gvInventory named colDifference which
shows difference of orderedQty-Received?
我建议您创建一个 Unbound Column in GridView and then calculate your difference at ColumnView.CustomUnboundColumnData 活动。请参阅下面的示例代码片段:
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
private void Form1_Load(object sender, System.EventArgs e) {
// ...
gridControl1.ForceInitialize();
// Create an unbound column.
GridColumn unbColumn = gridView1.Columns.AddField("Total");
unbColumn.VisibleIndex = gridView1.Columns.Count;
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
// Disable editing.
unbColumn.OptionsColumn.AllowEdit = false;
// Specify format settings.
unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
unbColumn.DisplayFormat.FormatString = "c";
// Customize the appearance settings.
unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
}
// Returns the total amount for a specific row.
decimal getTotalValue(GridView view, int listSourceRowIndex) {
decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"));
decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity"));
decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount"));
return unitPrice * quantity * (1 - discount);
}
// Provides data for the Total column.
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
GridView view = sender as GridView;
if (e.Column.FieldName == "Total" && e.IsGetData) e.Value =
getTotalValue(view, e.ListSourceRowIndex);
}
参考文献:
How to create and populate an unbound column
DevExpress GridControl Unbound Columns
To show Total of diffQty at Bottom of gridView
来源: Total Summary
GridColumn.SummaryItem 属性 是一个 GridSummaryItem 对象,它允许您根据汇总计算的值设置字段、应用于字段值的聚合函数和汇总值格式。下图显示了如何分别通过 GridSummaryItem.SummaryType
和 GridSummaryItem.DisplayFormat
属性自定义列摘要类型和显示格式。
示例:
colUnitsInStock1.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
colUnitsInStock1.SummaryItem.DisplayFormat = "Sum= {0:n2}";
要了解更多信息,请阅读 Summaries Overview 主题。
我正在使用 Devexpress 自定义 AX POS
打开 POS >> 收银任务 >> 取货 >> 转入/转出
在这里,我需要在 gvInventory 中添加一个名为 colDifference 的新列,它显示 orderedQty-Received
的差异
我还需要在 gridView
I need to add a new column in gvInventory named colDifference which shows difference of orderedQty-Received?
我建议您创建一个 Unbound Column in GridView and then calculate your difference at ColumnView.CustomUnboundColumnData 活动。请参阅下面的示例代码片段:
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
private void Form1_Load(object sender, System.EventArgs e) {
// ...
gridControl1.ForceInitialize();
// Create an unbound column.
GridColumn unbColumn = gridView1.Columns.AddField("Total");
unbColumn.VisibleIndex = gridView1.Columns.Count;
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
// Disable editing.
unbColumn.OptionsColumn.AllowEdit = false;
// Specify format settings.
unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
unbColumn.DisplayFormat.FormatString = "c";
// Customize the appearance settings.
unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
}
// Returns the total amount for a specific row.
decimal getTotalValue(GridView view, int listSourceRowIndex) {
decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"));
decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity"));
decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount"));
return unitPrice * quantity * (1 - discount);
}
// Provides data for the Total column.
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
GridView view = sender as GridView;
if (e.Column.FieldName == "Total" && e.IsGetData) e.Value =
getTotalValue(view, e.ListSourceRowIndex);
}
参考文献:
How to create and populate an unbound column
DevExpress GridControl Unbound Columns
To show Total of diffQty at Bottom of gridView
来源: Total Summary
GridColumn.SummaryItem 属性 是一个 GridSummaryItem 对象,它允许您根据汇总计算的值设置字段、应用于字段值的聚合函数和汇总值格式。下图显示了如何分别通过 GridSummaryItem.SummaryType
和 GridSummaryItem.DisplayFormat
属性自定义列摘要类型和显示格式。
示例:
colUnitsInStock1.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
colUnitsInStock1.SummaryItem.DisplayFormat = "Sum= {0:n2}";
要了解更多信息,请阅读 Summaries Overview 主题。