合計行専用のグリッドを別に作成し、入力用グリッドの下に表示するようにしてみました。
行列の固定時に同期する機能は未実装です。
依然としてスクロールバーを同期させる方法が怪しいですが。
Code:
{import * from COM.CURL.SONNTAG.LIB}
{define-proc public {get-grid-hscroll grid:RecordGrid}:#Scrollbar
let hscroll:#Scrollbar = null
{walk-graphics
grid,
ensure-ui-generated? = true,
{proc {g:Graphic}:void
{type-switch g
case sb:Scrollbar do
{if sb.direction == Orientation.horizontal then
set hscroll = sb
}
}
}
}
{return hscroll}
}
{def rfs =
{RecordFields
{RecordField "1", domain = String},
{RecordField "2", domain = String},
{RecordField "3", domain = String},
{RecordField "4", domain = String},
{RecordField "5", domain = String},
{RecordField "6", domain = String},
{RecordField "7", domain = String},
{RecordField "8", domain = String},
{RecordField "9", domain = String},
{RecordField "10", domain = String},
{RecordField "11", domain = String},
{RecordField "12", domain = String}
}
}
{let rs:RecordSet = {RecordSet rfs }}
{let sum-rs:RecordSet = {RecordSet rfs}}
{def rg =
{RecordGrid
record-source = rs,
width = {make-elastic},
display-navigation-panel? = false
}
}
{def sum-rg =
{RecordGrid
editable? = false,
record-source = sum-rs,
width = {make-elastic},
display-navigation-panel? = false,
display-column-headers? = false,
height = 30pt
}
}
{def v =
{View
width = 5in, height = 5in,
{Frame
width = {make-elastic},
height = {make-elastic},
hstretch? = true,
vstretch? = true,
{VBox rg, sum-rg}
}
}
}
{do
{v.show}
set (rg.ui-object asa RecordGridUI ).margin = 0pt
set (sum-rg.ui-object asa RecordGridUI ).margin = 0pt
{for i:int = 0 to 50 do
def r = {rs.new-record}
{rs.append r}
}
{rs.commit}
def sum-r = {sum-rs.new-record}
{sum-rs.append sum-r}
{sum-rs.commit}
||合計計算
{rs.add-event-handler
{on e:RecordModified do
{if-non-null rf = e.field then
let sum:int = 0
{for r in rs do
def s = {String r[rf.name] }
set sum = sum + {s.to-int}
}
{if-non-null sum-r = {sum-rs.select-one} then
set sum-r[rf.name] = {String sum}
}
}
}
}
||スクロールバーの同期設定
{if-non-null
hscrl1 = {get-grid-hscroll rg},
hscrl2 = {get-grid-hscroll sum-rg}
then
set hscrl1.visible? = false
set hscrl1.parent.height = 0pt
{hscrl1.add-event-handler
{on e:Adjustment at s:Scrollbar do
{hscrl2.set-scroll-value {s.get-scroll-value}}
}
}
{hscrl2.add-event-handler
{on e:Adjustment at s:Scrollbar do
{hscrl1.set-scroll-value {s.get-scroll-value}}
}
}
}
}