以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 最大值问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=105381) |
||||
-- 作者:douglas738888 -- 发布时间:2017/8/18 10:00:00 -- 最大值问题 请教老师,如何从合计列挑选出最大值,并把该行对应的项目名称填入到最后一列
|
||||
-- 作者:有点甜 -- 发布时间:2017/8/18 10:12:00 -- Dim dtr As DataRow = e.DataRow Select Case e.DataCol.Name Case "A","B","C","D" Dim Names() As String = {"A","B","C","D"} Dim maxname As String Dim maxvalue As Double = 0 For Each Name As String In Names If e.DataRow(name) > maxValue Then maxName = name maxValue = e.DataRow(name) End If Next If maxname > "" Then e.DataRow("最大值") = maxvalue e.DataRow("合计最大值项目名称") = maxName Else e.DataRow("最大值") = Nothing e.DataRow("合计最大值项目名称") = Nothing End If dtr("合计") = dtr("A") + dtr("B") + dtr("C") + dtr("D") End Select |
||||
-- 作者:douglas738888 -- 发布时间:2017/8/18 10:22:00 -- 谢谢老师指导,可能是我表达有误,合计最大值项目名称的列,填入的不是当前行最大值的列名,而是合计列中最大值对应行的项目名称,谢谢
项目名称 A B C D 合计 合计最大值项目名称 AA 1 2 3 4 10 BB 1 2 3 5 11 BB CC 1 2 3 3 9
用这段代码可以实现,怎样合并到老师指导的代码中 For Each r As Row In Tables("表A").Rows [此贴子已经被作者于2017/8/18 10:48:34编辑过]
|
||||
-- 作者:有点甜 -- 发布时间:2017/8/18 11:17:00 -- Dim dtr As DataRow = e.DataRow Select Case e.DataCol.Name Case "A","B","C","D" Dim Names() As String = {"A","B","C","D"} Dim maxname As String Dim maxvalue As Double = 0 For Each Name As String In Names If e.DataRow(name) > maxValue Then maxName = name maxValue = e.DataRow(name) End If Next If maxname > "" Then e.DataRow("最大值") = maxName Else e.DataRow("最大值") = Nothing End If dtr("合计") = dtr("A") + dtr("B") + dtr("C") + dtr("D") Case "合计" Dim fdr As DataRow = e.DataTable.Find("", "合计 desc") e.DataTable.ReplaceFor("合计最大值项目名称", fdr("项目名称")) End Select |