如何在DATAGRID控件中,某一字段修改时只能选固定的三个值,如(-,X,*)

kenyonzhang 2006-03-22 03:47:29
先说谢谢了!
...全文
103 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
faysky2 2006-03-22
  • 打赏
  • 举报
回复
用listBox来组合吧,看看这里有没有用:
http://www.hosp.ncku.edu.tw/~cww/html/q00184.html
kenyonzhang 2006-03-22
  • 打赏
  • 举报
回复
谢绝faysky2,但我想,在修改的时候能不能给他一个下拉列表框,而列表框中只有这三个字符?
faysky2 2006-03-22
  • 打赏
  • 举报
回复
如果限制那个字段只能输入一个字符,可以这样写 :

Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If DataGrid1.Col <> 2 Then Exit Sub '限制第3列的数据为(-,X,*)
If KeyAscii = 8 Then Exit Sub
If Len(DataGrid1.Text) > 0 And DataGrid1.SelLength = 0 Then '限制只能输入一个字符
KeyAscii = 0
Exit Sub
End If
If KeyAscii <> Asc("-") And KeyAscii <> Asc("X") And KeyAscii <> Asc("*") Then
KeyAscii = 0
End If
End Sub
faysky2 2006-03-22
  • 打赏
  • 举报
回复
参考:
Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If DataGrid1.Col <> 2 Then Exit Sub '限制第3列的数据为(-,X,*)
If KeyAscii = 8 Then Exit Sub
If KeyAscii <> Asc("-") And KeyAscii <> Asc("X") And KeyAscii <> Asc("*") Then
KeyAscii = 0
End If
End Sub

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧