关于在mshflexgrid中编辑的问题?
我想在mshflexgrid中进行数据的修改,可是某字段的值只充许几种可能的值,我如果让用户随便改就满足数据库的约束了,比如修改部门编码[我只是举个例子,比如某员工换部门了,就是修改员工档案表中的部门编码字段。],如果用户改对了还好,如果用户不小心输入的一个不存在的部门编码,那么就不行了。可是如何在表格的编辑中进行约束呢。我添加记录的方式是从一个组合框中取的值,然后添加到数据表中去的。因为当时是从组合框中选的。所以不会出错。可是我修改记录时是在表格中修改,如何处理这类问题呢?
注:我以上只是举个例子,您可能会告诉我不要这样改部门编码。可是我假定只能这样从表格中改时应该如何去约束用户的输入呢?
谢各位了。先。
我想在mshflexgrid中进行数据的修改,可是某字段的值只充许几种可能的值,我如果让用户随便改就满足数据库的约束了,比如修改部门编码[我只是举个例子,比如某员工换部门了,就是修改员工档案表中的部门编码字段。],如果用户改对了还好,如果用户不小心输入的一个不存在的部门编码,那么就不行了。可是如何在表格的编辑中进行约束呢。我添加记录的方式是从一个组合框中取的值,然后添加到数据表中去的。因为当时是从组合框中选的。所以不会出错。可是我修改记录时是在表格中修改,如何处理这类问题呢?
注:我以上只是举个例子,您可能会告诉我不要这样改部门编码。可是我假定只能这样从表格中改时应该如何去约束用户的输入呢?
谢各位了。先。
免费的学习交流网站,欢迎大家访问!
http://www.j2soft.cn/
完全可以在msflexgrid中进行限制。Private Sub MSFlexGrid1_Click()
If MSFlexGrid1.Col = 3 Then
If Text1.Visible = False Then
Text1.Visible = True
Text1.Enabled = True
End If
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left + 2
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top - 2
Text1.Width = MSFlexGrid1.CellWidth - 3
Text1.Text = MSFlexGrid1.Text
If Len(Text1.Text) > 0 Then
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
Else
Text1.Visible = False
End If
End Sub
' Exit Sub
'End IfText1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left + 2
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top - 2
Text1.Width = MSFlexGrid1.CellWidth - 3Text1.Text = MSFlexGrid1.Text
If Text1.Visible = True Then
If Len(Text1.Text) > 0 Then
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End IfMSFlexGrid1_Click
End Sub
Private Sub MSFlexGrid1_GotFocus()
If Text1.Visible = True Then
Text1.SetFocus
End IfEnd SubPrivate Sub MSFlexGrid1_LeaveCell()
If MSFlexGrid1.Row > 0 And MSFlexGrid1.Row < 5 Then
Select Case ChkRow(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2), MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 3), MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 5))
Case 1 '范围外
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4) = "不合格"
Case 0 '范围内
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4) = "合格"
Case -1 '无法CHK
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4) = ""
End Select
End If
End Sub
If MSFlexGrid1.Row > 0 Then
If Len(Text1.Text) > 0 Then
If Text1.Text = "." Then Exit Sub
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col + 2) <> "-1" Then
If Not IsNumeric(Text1.Text) Then
MsgBox "要求数字。...", vbInformation, "提示"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
Else
If CDbl(Text1.Text) < 0 Then
MsgBox "输入数值非法。", vbInformation, "提示"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
End If
Else
End If
End If
End If
End If
If (isFind = True) And (MSFlexGrid1.Text <> Text1.Text) Then
isChanged = True '查询模式中,记录有被修改。
End IfIf MSFlexGrid1.Row = 5 Then
MSFlexGrid1.Text = ""
Exit Sub
End If'格式化代码
Select Case MSFlexGrid1.Col
Case 0
MSFlexGrid1.Text = Text1.Text
Case 1
MSFlexGrid1.Text = Format(Text1.Text, "0.0000")
Case 3
MSFlexGrid1.Text = Text1.Text
End Select
'If Len(MSFlexGrid1.Text) > 0 Then
' If MSFlexGrid1.Row = MSFlexGrid1.Rows - 1 And MSFlexGrid1.Col = 0 Then
' MSFlexGrid1.AddItem ""
' End If
'End IfEnd Sub
Case 0
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
Case 1
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
Case 2
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
Case 3
CompSB = False
Combo6.Visible = True
Text1.Visible = False
Command3.Visible = True
Combo6.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left + 2
Combo6.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top - 2
Combo6.Width = MSFlexGrid1.CellWidth - 3 - MSFlexGrid1.CellHeight 'MSFlexGrid1.CellHeight260为Button所留 Command3.Left = Combo6.Left + Combo6.Width - 15
Command3.Height = 255
Command3.Width = 270
Command3.Top = Combo6.Top + 10
Combo6.Clear
Combo6.Text = ""
Combo6.AddItem ""
SqlStr = "select * from SetJCBZ where 项目名称='" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) & "'"
Set Rs = Cn.Execute(SqlStr)
Do While Not Rs.EOF
Combo6.AddItem Rs!所属标准
Rs.MoveNext
Loop
Combo6.Text = MSFlexGrid1.Text
Case 4
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
Case 5 '检测结果
CompSB = True '比较标志,决定是否进行比较
Combo6.Visible = False
Command3.Visible = False
Text1.Visible = True
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left + 2
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top - 2
Text1.Width = MSFlexGrid1.CellWidth - 3
Text1.Text = MSFlexGrid1.Text
Text1.Height = MSFlexGrid1.CellHeight
If Len(Text1.Text) > 0 Then
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
Case 6
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
Case 7
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
Case 8
CompSB = False
Text1.Visible = False
Combo6.Visible = False
Command3.Visible = False
End SelectEnd Sub