如:要用代号来查询选出名称, 下面是我写的一个用户自定义控件,可以有三种方式
来查询,一:利用要查出资料的任何一列来进行模糊查找(代号或助记码或名称);
二:利用选择任一个列来查询(在选择框中选择代号或助记码或名称);三:设计时
固定来哪一个列用于查询(如设只能用代号来查询),下面是一部分代号,如果谁需
要更详细的设计方法,请与作者联系,QQ:41677881。
'查找种类
Public Enum emFindStyle As Integer
AllFindKey = 1 '全部
OneFindKey = 2 '只有一个,可以在查询框选择
OneFixedKey = 3 '只有一个,编程时设定
End Enum
'显示风格
Public Enum emShowStyle As Integer
KeyDownShow = 1 'KeyDown显示查询框
GotFocusShow = 2 'GotFocus显示查询框
End Enum
Public Class MySmartFind
#Region " 构造函数 "
Sub New()
' 此调用是 Windows 窗体设计器所必需的。
InitializeComponent()
' 在 InitializeComponent() 调用之后添加任何初始化。
'属性预设值
Me.NoText = "预设代号"
Me.NoControlWidth = 100
Me.NoColumnName = ""
Me.NoColumnWidth = Me.txtNo.Width '100
Me.NameText = "预设名称"
Me.NameColumnName = ""
Me.NameColumnWidth = Me.labName.Width '250
Me.FindStyle = emFindStyle.AllFindKey
Me.OneFindKeyColumn = ""
Me.ShowStyle = emShowStyle.KeyDownShow
Me.DistinguishUpperAndLower = False
End Sub
#End Region
#Region " 变量 "
'变量
Private _NoText As String '代号
Private _NoControlWidth As Integer '代号控件宽度
Private _NoColumnName As String '代号列名
Private _NoColumnWidth As Integer '代号列宽度
Private _NameText As String '名称
Private _NameColumnName As String '名称列名
Private _NameColumnWidth As Integer '名称列宽度
Private _DataSource As DataTable '数据源
Private _FindStyle As emFindStyle '查询方式
Private _OneFindKeyColumn As String '唯一下个查询键字段名
Private _ShowStyle As emShowStyle '何时显示查询框
Private _DistinguishUpperAndLower As Boolean '区别大小写
Private _frmSmartFind As frmSmartFind '查询窗体
Private intFocusFlag As Integer 'GotFocus是否起用标志
#End Region
#Region " 属性 "
'属性
Public Property NoText() As String
Get
Return _NoText
End Get
Set(ByVal value As String)
Try
If value Is Nothing Then
value = ""
Else
value = CType(value, String)
End If
Catch ex As Exception
Throw New Exception("NoText必须为String类型")
End Try
_NoText = value
txtNo.Text = _NoText
End Set
End Property
Public Property NoControlWidth() As Integer
Get
Return _NoControlWidth
End Get
Set(ByVal value As Integer)
_NoControlWidth = value
txtNo.Width = _NoControlWidth
'labName.Width = labName.Width - _NoWidth
labName.Location = New Point(txtNo.Location.X + _NoControlWidth, labName.Location.Y)
End Set
End Property
Public Property NoColumnName() As String
Get
Return _NoColumnName
End Get
Set(ByVal value As String)
Try
If value Is Nothing Then
value = ""
Else
value = CType(value, String)
End If
Catch ex As Exception
Throw New Exception("NoColumn必须为String类型")
End Try
_NoColumnName = value
End Set
End Property
Public Property NoColumnWidth() As Integer
Get
Return _NoColumnWidth
End Get
Set(ByVal value As Integer)
_NoColumnWidth = value
End Set
End Property
Public Property NameText() As String
Get
Return _NameText
End Get
Set(ByVal value As String)
Try
If value Is Nothing Then
value = ""
Else
value = CType(value, String)
End If
Catch ex As Exception
Throw New Exception("NameText必须为String类型")
End Tr

















