Syntax
Private Sub VSFlexGrid_BeforeRowColChange( ByVal OldRow As Long, ByVal OldCol As Long, ByVal NewRow As Long, ByVal NewCol As Long, Cancel As Boolean)
Example:
‘ cancel if new cell is in protected area
Private Sub fg_BeforeRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, _
ByVal NewRow As Long, ByVal NewCol As Long, Cancel As Boolean)
If NewRow >= 2 And NewRow <= 8 And NewCol >= 2 And NewCol <= 4 Then Cancel = True
End Sub
‘ cancel if new selection is on protected area
Private Sub fg_BeforeSelChange(ByVal OldRowSel As Long, ByVal OldColSel As Long, _
ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
If (fg.Row < 2 And NewRowSel < 2) Or (fg.Col < 2 And NewColSel < 2) Then Exit Sub
If (fg.Row > 8 And NewRowSel > 8) Or (fg.Col > 4 And NewColSel > 4) Then Exit Sub
Cancel = True
End Sub
ComObjConnect() [v1.0.90+]
……
Usage
To make effective use of ComObjConnect, you must first write functions in the script to handle any events of interest. Such functions, or “event-handlers,” have the following structure:
PrefixEventName([Params…, ComObject])
{
… event-handling code …
return ReturnValue
}
……
ComObject is optional, and can only be used if the correct number of Params are defined; it contains a reference to the original wrapper object which was passed to ComObjConnect. “ComObject” should be replaced with a name more meaningful in the context of your script.
Note that event handlers may have return values. To return a COM-specific type of value, use ComObject(type, value). For example, return ComObject(0,0) returns a variant of type VT_EMPTY, which is equivalent to returning undefined (or not returning) from a JavaScript function.
Class MainFormGui extends GuiBase { Init() { this.data:={"Payments_id":0,"PayForm_id":0 ,"StatusBarInfo":"" ,"ddl_month":{"list":[1,2,3,4,5,6,7,8,9,10,11,12],"choose":A_MM*1} ,"ddl_sender":{"list":["全部"],"choose":1} ,"ddl_receiver":{"list":["全部"],"choose":1} ,"ddl_handoverList":{"list":["全部"],"choose":1} ,"ddl_CheckedList":{"list":["全部","待报送","待接收","已接收"],"choose":1} ,"fg_payments":{"Headers":[" 编号","日期","用途","金额","科室","经办人","收款账户","备注"] ,"data":this.fgPaymentsEvents.GridData,count:0,sum:0}} this.Font("s14","宋体") this.sb := this.AddStatusBar() this.AddText("x10 y8 w60 h23 ","期间:") this.ddl_month := this.AddDropDownList("x70 y6 w50 h23 r12", this.data.ddl_month.list).OnEvent(this.ddl_monthChange.Bind(this)) this.AddText("x140 y8 w80 h23 ","报账员:") this.ddl_sender := this.AddDropDownList("x210 y6 w100 h23 r10 AltSubmit").OnEvent(this.ddl_senderChange.Bind(this)) this.AddText("x330 y8 w80 h23 ","接收人:") this.ddl_receiver := this.AddDropDownList("x410 y6 w100 h23 r10 AltSubmit").OnEvent(this.ddl_receiverChange.Bind(this)) this.AddText("x530 y8 w80 h23 ","移交单:") this.ddl_handoverList := this.AddDropDownList("x610 y6 w160 h23 r10 AltSubmit").OnEvent(this.handoverListChange.Bind(this)) this.AddText("x790 y8 w60 h23 ","状态:") this.ddl_CheckedList := this.AddDropDownList("x850 y6 w100 h23 r4 AltSubmit",this.data.ddl_CheckedList.list).OnEvent(this.ddl_CheckedListChange.Bind(this)) ;数据表,使用ComponentOne FlexGrid8组件。 this.fg_payments := this.AddFlexGrid("x10 y36 w1180 h500",this.data.fg_payments.Headers) this.fg_payments.ConnectEvents(MainFormGui.fgPaymentsEvents) Captions := {"add":"新增","modify":"修改","save":"保存","delete":"删除","cancle":"取消"} this.fg_payments.CRUD := this.AddCRUDButtonGroup("x10 y536 w200 h36",Captions,[this.fg_payments.ax,this.fgPaymentsEvents.onSave.Bind(this)]) this.Refresh() } ...... class fgPaymentsEvents{ static ax static GridData:=ComObjArray(VT_VARIANT:=12,8,50,10) Init(){ this.ax.FontSize := 14 ;~ this.ax.Editable := True this.ax.AutoResize := True this.ax.AllowUserResizing := (flexResizeColumns:=1) this.ax.FixedCols := 0 this.ax.ColWidthMin := 1200 this.ax.ColDataType(3) := (FlexDTCurrency:=6) this.ax.ColFormat(3) := "$#,###.00" this.ax.ColEditMask(3) := "#########.##" this.ax.ColAlignment(3):= (FlexAlignRightCenter:=7) this.ax.ColDataType(9) := flexdtBoolean this.ax.ColDataType(10) := flexdtBoolean ;~ this.ax.ColComboList(5) := c_Data.get_person_comboList() ;~ this.ax.ColComboList(6) := c_Data.get_bank_comboList() this.ax.ComboSearch := (FlexCmbSearchAll:=3) ;~ this.ax.ColComboList(1) := "North|South|East|West" ;~ this.ax.ColComboList(2) := "|Mary|Paula|Sarah" ;~ this.GridData:=ComObjArray(VT_VARIANT:=12,this.ax.Cols,GridPaymentsRows,10) this.ax.BindToArray(this.GridData) } BindToData(dataSrc){ this.dataSrc:=dataSrc } onSave(){ ; return true } BeforeRowColChange( OldRow, OldCol, NewRow, NewCol, ByRef Cancel){ if(this.ax.Editable && OldRow!=NewRow){ Cancel:=ComObject(0xB,-1) } } } }
GUI用了第三方库AHK-Object-Oriented-GUIs-master。
关于FlexGrid控件自己作了扩展。
用面向对象的方式来写界面,比原生AHK GUI函数舒服多了。贴一下我扩展的FlexGrid控件类。
不错 用空测试一下