如何将加权平均摘要添加到 DevExpress XtraGrid?
DevExpress 网格(XtraGrid)允许网格及其组进行汇总计算。 可用选项有计数、最大值、最小值、平均值、总和、无和自定义。
有没有人获得一些示例代码,显示如何根据另一列中作为值提供的权重来计算加权平均列?
The DevExpress Grid (XtraGrid) allows grids and their groups to have summary calculations. The available options are Count, Max, Min, Avg, Sum, None and Custom.
Has anyone got some sample code that shows how to calculate a weighted average column, based upon the weightings provided as values in another column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终解决了这个问题,并将在这里发布我的解决方案,以防其他人发现它有用。
如果加权平均值由每行的值和权重组成,则包含该值的列应将权重 GridColumn 对象分配给其 Tag 属性。 然后,此事件处理程序将完成剩下的工作:
代码假定基础列值可以通过
Convert.ToDouble(object)
转换为双精度值。I ended up working this out, and will post my solution here in case others find it useful.
If a weighted average consists of both a value and a weight per row, then column that contains the value should have the weight GridColumn object assigned to its Tag property. Then, this event handler will do the rest:
The code assumes that the underlying column values can be converted to doubles via
Convert.ToDouble(object)
.如果您在总和中提供自己的 lambda 表达式,您应该能够按标准总和对它们进行分组。 我认为这应该有效:
If you provide your own lambda expression inside the sum you should be able to group them by a standard sum. I think this should work: