我在程序中使用了mshflexgrid控件来显示ado取得的数据:
mshflexgrid.clear
set mshflexgrid.datasource=adors
而且我已经设置mshflexgrid的selectionmode属性为FlexSelectionByRow。但我用鼠标单击mshflexgrid想选中某行时,却选中的是上面一行。比如,我想选中第三行,却选中了第二行。我知道使用其它datagird控件能够解决这个问题。但使用mshflexgrid为什么有时会出现这个情况呢???
mshflexgrid.clear
set mshflexgrid.datasource=adors
而且我已经设置mshflexgrid的selectionmode属性为FlexSelectionByRow。但我用鼠标单击mshflexgrid想选中某行时,却选中的是上面一行。比如,我想选中第三行,却选中了第二行。我知道使用其它datagird控件能够解决这个问题。但使用mshflexgrid为什么有时会出现这个情况呢???
If .MouseCol < .FixedCols And .MouseRow > 0 Then
.Row = .MouseRow '可準確定義你選中的行
end
end with
mshflexgrid.clear
Dim adotp As ADODB.Recordset
Dim conntp As ADODB.Connection
Dim adotpmx As ADODB.Recordset
Dim conntpmx As ADODB.Connection
Dim adosp_tp As ADODB.Recordset
Dim connsp_tp As ADODB.Connection
Dim tpBH As String '套票编号
Dim zong '总金额
Dim prt_filter_jhdj As String
Dim state As String
Dim state_mx As String
Dim yue_temp As String
Dim nian_temp As String
Dim i As IntegerPrivate Sub cmdadd_Click()
If cmdsave_mx.Enabled = True Then
MsgBox "请先完成套票内容的录入操作!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
state = "add"
txthj.Text = "0.00"
cmd_dj_false
txt_dj_true
txtbh.Text = ""
txtghs.Text = ""
txtbh.SetFocus
End SubPrivate Sub cmdadd_mx_Click()
If cmdsave.Enabled = True Then
MsgBox "请先完成正在进行的套票操作!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
If txtbh.Text = "" Then
MsgBox "请先选择套票记录!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
frmspxz_tp.Show
frmspxz_tp.txtflag.Text = "5"
End SubPrivate Sub cmdcancel_Click()
If state = "add" Then
txtbh.Text = ""
txthj.Text = ""
txtghs.Text = ""
cmd_dj_true
txt_dj_false
state = ""
Exit Sub
End If
If state = "edit" Then
adotp.Filter = "套票编号 = '" & txtbh.Text & "'"
If adotp.RecordCount > 0 Then
txtbh.Text = adotp.Fields(0)
txtghs.Text = adotp.Fields(1)
txthj.Text = Format(adotp.Fields(2), "#0.00")
Else:
txtbh.Text = ""
txthj.Text = ""
txtghs.Text = ""
End If
fgdj.Clear
adotp.Filter = adFilterNone
Set fgdj.DataSource = adotp
cmd_dj_true
txt_dj_false
state = ""
End If
End Sub
If state_mx = "edit" Then
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "' and 商品编号 = '" & txtspbh.Text & "'"
If adotpmx.RecordCount > 0 Then
txtspbh.Text = adotpmx.Fields(1)
txtpm.Text = adotpmx.Fields(2)
txtdw.Text = adotpmx.Fields(3) + ""
txtdj.Text = Format(adotpmx.Fields(4), "#0.00")
txtsl.Text = Format(adotpmx.Fields(5), "#0.00")
txtje.Text = Format(adotpmx.Fields(6), "#0.00")
txttc.Text = Format(adotpmx.Fields(7), "#0.00")
txtzhong.Text = Format(adotpmx.Fields(8), "#0.00")
End If
Else:
txtspbh.Text = ""
txtpm.Text = ""
txtdw.Text = ""
txtdj.Text = ""
txtsl.Text = ""
txtje.Text = ""
txttc.Text = ""
txtzhong.Text = ""
End If
txttc.Enabled = False
cmd_mx_true
state_mx = ""
txtdj.Enabled = False
txtsl.Enabled = False
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "'"
Set fgmx.DataSource = adotpmx
End SubPrivate Sub cmddel_Click()
If txtbh.Text = "" Then
MsgBox "请先选择套票记录!", vbOKOnly + vbExclamation, "操作错误"
Exit Sub
End If
If MsgBox("的确要删除该套票记录吗?", vbYesNo + vbQuestion, "删除操作") = vbNo Then
Exit Sub
End If
adotp.Requery
adotp.Filter = "套票编号 = '" & txtbh.Text & "'"
If adotp.RecordCount > 0 Then
adotp.Delete
'删除对应商品资料
adosp_tp.Requery
adosp_tp.Filter = "套票标记 = '" & txtbh.Text & "'"
If adosp_tp.RecordCount > 0 Then
adosp_tp.Delete
End If
Else:
MsgBox "所选单据不存在!", vbOKOnly + vbExclamation, "操作提示"
End If
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "'"
If adotpmx.RecordCount > 0 Then
adotpmx.MoveFirst
Do Until adotpmx.EOF
adotpmx.Delete
adotpmx.MoveNext
Loop
End If
'记录日志
gen_riqi
Cn_rizhi.Open cntstrbigeye
Sql_rizhi = "insert into sysTmanager (编号,系统日志,标记) values ('" & RqTime & "','删除套票记录" + txtbh.Text + "。时间:" & tempdate & temptime & "。操作人员姓名:" & username & "','F')"
Cn_rizhi.Execute Sql_rizhi
Sql_rizhi = ""
Cn_rizhi.Close
txtbh.Text = ""
txthj.Text = ""
txtghs.Text = ""
Frame2.Caption = "套票明细"
adotp.Requery
adotp.Filter = adFilterNone
adotp.Sort = "套票编号"
Set fgdj.DataSource = adotp
End SubPrivate Sub cmddel_mx_Click()
If cmdsave.Enabled = True Then
MsgBox "请先完成正在进行的套票操作!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
If txtspbh.Text = "" Then
MsgBox "请先选择商品记录!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
'删除记录
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "' and 商品编号 = '" & txtspbh.Text & "'"
If adotpmx.RecordCount > 0 Then
adotpmx.Delete
End If
'刷新显示,并重新计算总金额
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "'"
Set fgmx.DataSource = adotpmx
fgmx.Row = 0
fgmx.Col = 0
'计算该套票总金额
zong = 0
If adotpmx.RecordCount > 0 Then
adotpmx.MoveFirst
Do Until adotpmx.EOF
zong = zong + adotpmx.Fields(6)
adotpmx.MoveNext
Loop
End If
txthj.Text = Format(zong, "#0.00")
adotp.MoveFirst
adotp.Filter = "套票编号 = '" & txtbh.Text & "'"
If adotp.RecordCount > 0 Then
adotp.Fields(2) = zong
adotp.Update
End If
'修改对应的品项价格
adosp_tp.Requery
adosp_tp.Filter = "套票标记 = '" & txtbh.Text & "'"
If adosp_tp.RecordCount > 0 Then
adosp_tp.Fields(5) = zong
adosp_tp.Fields(6) = zong
adosp_tp.Update
End If
'记录日志
gen_riqi
Cn_rizhi.Open cntstrbigeye
Sql_rizhi = "insert into sysTmanager (编号,系统日志,标记) values ('" & RqTime & "','删除套票" + txtbh.Text + "的一条明细记录。时间:" & tempdate & temptime & "。操作人员姓名:" & username & "','F')"
Cn_rizhi.Execute Sql_rizhi
Sql_rizhi = ""
Cn_rizhi.Close
adotp.Filter = adFilterNone
adotp.Sort = "套票编号"
Set fgdj.DataSource = adotp
txtspbh.Text = ""
txtpm.Text = ""
txtdw.Text = ""
txtdj.Text = ""
txtsl.Text = ""
txtje.Text = ""
txttc.Text = ""
txtzhong.Text = ""
End Sub
If cmdsave_mx.Enabled = True Then
MsgBox "请先完成套票内容录入操作!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
If txtbh.Text = "" Then
MsgBox "请选择套票记录!", vbOKOnly + vbExclamation, "操作错误"
Exit Sub
End If
state = "edit"
cmd_dj_false
txt_dj_true
txtbh.Enabled = False
End SubPrivate Sub cmdedit_mx_Click()
If cmdsave.Enabled = True Then
MsgBox "请先完成正在进行的套票操作!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
If txtspbh.Text = "" Then
MsgBox "请先选择商品记录!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
txtdj.Enabled = True
txtsl.Enabled = True
txttc.Enabled = True
If Left(txtbh.Text, 1) = "K" Then
txtzhong.Enabled = True
End If
state_mx = "edit"
cmd_mx_false
End Sub
Private Sub cmdquit_Click()
Unload Me
End Sub
Private Sub cmdsave_Click()
If txtbh.Text = "" Then
MsgBox "请输入套票编号!", vbOKOnly + vbExclamation, "操作错误"
Exit Sub
End If
If IsNumeric(txtbh.Text) = False Then
MsgBox "编号只允许数字形式,请重新输入!", vbOKOnly + vbExclamation, "输入错误"
Exit Sub
End If
If state = "add" Then
adotp.Requery
adotp.Filter = "套票编号 = '" & txtbh.Text & "'"
If adotp.RecordCount > 0 Then
MsgBox "该编号已经存在,请重新输入!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
adotp.AddNew
adotp.Fields(0) = txtbh.Text
adotp.Fields(1) = txtghs.Text + ""
adotp.Fields(2) = "0.00"
adotp.Update
fgdj.Clear
adotp.Filter = adFilterNone
adotp.Sort = "套票编号"
Set fgdj.DataSource = adotp
cmd_dj_true
txt_dj_false
state = ""
Frame2.Caption = "套票编号:" + txtbh.Text
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "'"
Set fgmx.DataSource = adotpmx
fgdj.SelectionMode = flexSelectionByRow
'将该套票资料加入品项基本资料
'生成编号
adosp_tp.Filter = "商品编号 like '" & "A99" & "*'"
If adosp_tp.RecordCount = 0 Then
tpBH = "A99001"
Else:
adosp_tp.Sort = "商品编号"
adosp_tp.MoveLast
tpBH = "A" + Trim(Str(Val(Mid(adosp_tp!商品编号, 2, 5)) + 1))
End If
adosp_tp.AddNew
adosp_tp.Fields(0) = tpBH
adosp_tp.Fields(1) = txtghs.Text
adosp_tp.Fields(2) = ""
adosp_tp.Fields(3) = ""
adosp_tp.Fields(4) = "套"
adosp_tp.Fields(5) = txthj.Text
adosp_tp.Fields(6) = txthj.Text
adosp_tp.Fields(7) = "0"
adosp_tp.Fields(8) = "0"
adosp_tp.Fields(13) = "tp"
adosp_tp.Fields(14) = "不限制"
adosp_tp!单位上限 = "0"
adosp_tp!上限金额 = "0"
adosp_tp!外购品项 = "否"
adosp_tp!参与折扣 = "否"
adosp_tp!套票标记 = txtbh.Text
adosp_tp.Update
'记录日志
gen_riqi
Cn_rizhi.Open cntstrbigeye
Sql_rizhi = "insert into sysTmanager (编号,系统日志,标记) values ('" & RqTime & "','增加套票记录" + tpBH + "。时间:" & tempdate & temptime & "。操作人员姓名:" & username & "','F')"
Cn_rizhi.Execute Sql_rizhi
Sql_rizhi = ""
Cn_rizhi.Close
Exit Sub
End If
If state = "edit" Then
adotp.Filter = "套票编号 = '" & txtbh.Text & "'"
If adotp.RecordCount > 0 Then
adotp.Fields(1) = txtghs.Text + ""
adotp.Update
adosp_tp.Requery
adosp_tp.Filter = "套票标记 = '" & txtbh.Text & "'"
If adosp_tp.RecordCount > 0 Then
adosp_tp.Fields(1) = txtghs.Text
adosp_tp.Update
'记录日志
gen_riqi
Cn_rizhi.Open cntstrbigeye
Sql_rizhi = "insert into sysTmanager (编号,系统日志,标记) values ('" & RqTime & "','修改套票记录" + txtbh.Text + "。时间:" & tempdate & temptime & "。操作人员姓名:" & username & "','F')"
Cn_rizhi.Execute Sql_rizhi
Sql_rizhi = ""
Cn_rizhi.Close
End If
Else:
MsgBox "所选套票不存在!", vbOKOnly + vbExclamation, "提示信息"
End If
adotp.Filter = adFilterNone
adotp.Sort = "套票编号"
Set fgdj.DataSource = adotp
fg_dj_inil
cmd_dj_true
txt_dj_false
state = ""
fgdj.SelectionMode = flexSelectionByRow
End If
End Sub
MSHFlexGrid1.TextMatrix(MSHFlexGrid2.Row, 1)
这就是你想选择的那行内容.再变通一下
Private Sub fgdj_Click()
If cmdsave.Enabled = True Then
Exit Sub
End If
fgdj.Col = 0
If fgdj.Text = "" Or fgdj.Text = "套票编号" Then
Exit Sub
End If
If cmdsave_mx.Enabled = True Then
MsgBox "请先完成套票内容的录入操作!", vbOKOnly + vbExclamation, "提示信息"
Exit Sub
End If
txtbh.Text = fgdj.Text '套票编号
fgdj.Col = 1
txtghs.Text = fgdj.Text '套票名称
fgdj.Col = 2
txthj.Text = Format(fgdj.Text, "#0.00") '套票总金额
adotpmx.Requery '已经连接套票明细表的ado记录集
adotpmx.Filter = "套票编号 = '" & txtbh.Text & "'"
Set fgmx.DataSource = adotpmx
End Sub说明:鼠标单击fgdj的某一行,fgmx应该显示所选行的套票明细。实际结果是,有套票明细时,鼠标却不能从fgmx中准确选择某行数据,往往要差一行。有时好用,大多时不好用。