|
谢谢分享,大家所见略同,我也是使用这种方法, 不过写成了通用函数,方便设置不同列数 不同栏宽的组合框.
'===============================================================================
'-函数名称: gt_SetComboColumnWidth
'-功能描述: 设置组合框栏位宽度,进入时可按编码录入,离开时可显示名称
'-输入参数说明: 参数1:rctr Control 控件对象
' 参数2:rstrColumnWidths String 栏位宽度
'-返回参数说明: 无
'-使用语法示例: gt_SetComboColumnWidth cboCust,"3;2;4"
'-参考:
'-使用注意: 只适用Label TextBox CommandButton ComboBox OptionButton CheckBox
'-兼容性: 97,2000,XP,2003 compatible
'-作者: 王宇虹,改进:王宇虹
'-更新日期: 2004-08-24
'===============================================================================
Public Function gt_SetComboColumnWidth(rctr As Control, rstrColumnWidths As String)
On Error Resume Next
If TypeOf rctr Is ComboBox Then
rctr.ColumnWidths = rstrColumnWidths
' rctr.RowSource = rctr.RowSource
' rctr.Requery
End If
End Function
'===============================================================================-----天鸣科技--->>>>>>>>
'-函数名称: gt_SetCboEnterEvent
'-功能描述: 设置组合框的进入事件
'-输入参数: 参数1:rctrComboBox String 组合框控件
' 可选参数2:rintType Integer 方式
' 可选参数3:rstrTemp String 其它参数
'-返回参数: 无
'-使用示例: gt_SetCboEnterEvent cboCust,0
'-相关调用: 无
'-使用注意: 可设置是否自动弹出组合框,还是没有内容才弹出组合框
'-兼 容 性: 97,2000,XP,2003 compatible
'-参考资料:
'-作 者: 王宇虹 修改:王宇虹
'-创建日期; 2002-08-26 更新日期: 2002-08-28 ,2002-11-15
'-图 解:
'===============================================================================--<>>>>>
Public Function gt_SetCboEnterEvent(Optional rctrComboBox As Control, Optional rintType As Integer = 0, Optional rstrTemp As String)
Dim blnCancel As Boolean
Dim frm As Form
On Error Resume Next
If TypeOf rctrComboBox.Parent Is Form Then
Set frm = rctrComboBox.Parent
Else
If TypeOf rctrComboBox.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent
Else
If TypeOf rctrComboBox.Parent.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent.Parent
Else
Exit Function
End If
End If
End If
If frm Is Nothing Then Exit Function
If frm.CurrentView = 1 Then
If Nz(gt_GetParaItem("PopupWindow", rctrComboBox.Tag)) <> "" Or Nz(gt_GetParaItem("DropWindow", rctrComboBox.Tag)) <> "" Then
frm.cmdOpenSelWindow.Tag = frm.ActiveControl.name
frm.cmdOpenSelWindow.Left = frm.ActiveControl.Left + frm.ActiveControl.Width + 10
frm.cmdOpenSelWindow.Top = frm.ActiveControl.Top
If frm.AllowEdits = False Or frm.Controls(frm.cmdOpenSelWindow.Tag).Enabled = False Or frm.Controls(frm.cmdOpenSelWindow.Tag).Locked = True Then '
If frm.cmdOpenSelWindow.Object.Enabled = True Then
frm.cmdOpenSelWindow.Object.Enabled = False
End If
If frm.cmdOpenSelWindow.Visible = True Then
frm.cmdOpenSelWindow.Visible = False
End If
Else
If frm.cmdOpenSelWindow.Object.Enabled = False Then
frm.cmdOpenSelWindow.Object.Enabled = True
End If
If frm.cmdOpenSelWindow.Visible = False Then
frm.cmdOpenSelWindow.Visible = True
End If
End If
End If
End If
If Nz(rctrComboBox.ControlSource) <> "" Then
If frm.AllowEdits = False Or rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
Else
If rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
End If
If blnCancel Then Exit Function
If Nz(gt_GetParaItem("ComboStyle", rctrComboBox.Tag)) = "Autocbo" Then 'InStr(rctrComboBox.Tag, "autocbo") > 0
gt_SetComboColumnWidth rctrComboBox, rstrTemp
End If
Select Case rintType
Case 2
gt_ComboAutoExpand rctrComboBox, True
Case 1
gt_ComboAutoExpand rctrComboBox, False
Case 0
End Select
End Function
'===============================================================================-----天鸣科技--->>>>>>>>
'-函数名称: gt_SetCboExitEvent
'-功能描述: 设置组合框的离开事件
'-输入参数: 参数1:rctrComboBox String 组合框控件
' 可选参数2:rintType Integer 方式
' 可选参数3:rstrTemp String 其它参数
'-返回参数: 无
'-使用示例: gt_SetCboExitEvent cboCust,0
'-相关调用: 无
'-使用注意:
'-兼 容 性: 97,2000,XP,2003 compatible
'-参考资料:
'-作 者: 王宇虹 修改:王宇虹
'-创建日期; 2002-08-26 更新日期: 2002-08-28 ,2002-11-15
'-图 解:
'===============================================================================--<>>>>>
Public Function gt_SetCboExitEvent(Optional rctrComboBox As Control, Optional rintType As Integer = 0, Optional rstrTemp As String)
Dim blnCancel As Boolean
Dim frm As Form
On Error Resume Next
If TypeOf rctrComboBox.Parent Is Form Then
Set frm = rctrComboBox.Parent
Else
If TypeOf rctrComboBox.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent
Else
If TypeOf rctrComboBox.Parent.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent.Parent
Else
Exit Function
End If
End If
End If
If frm Is Nothing Then Exit Function
If Nz(rctrComboBox.ControlSource) <> "" Then
If frm.AllowEdits = False Or rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
Else
If rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
End If
If blnCancel Then Exit Function
If Nz(gt_GetParaItem("ComboStyle", rctrComboBox.Tag)) = "Autocbo" Then 'InStr(rctrComboBox.Tag, "autocbo") > 0
gt_SetComboColumnWidth rctrComboBox, rstrTemp
End If
End Function |
|