[VB.NET]datagridview CellValidating

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
datagridview CellValidating
想在 datagridview CellValidating 事件中验证数据·

如果验证失败,当前cell变为红色,焦点不离开。

我试了 Dim MyStyle As New DataGridViewCellStyle
MyStyle.BackColor = Color.Red
Me.CurrentCell.Style = MyStyle

因为有e.Cancel = True所以不成功。

用画笔,只能画出一个边框:
Dim width As Int32 = Me.Columns(Me.CurrentCell.ColumnIndex).Width - 1
Dim height As Int32 = Me.Rows(Me.CurrentCell.RowIndex).Height - 1
Dim x As Int32 = getCurrentX()
Dim y As Int32 = getCurrentY()
Dim rect As Rectangle
rect = New Rectangle(x, y, width, height)
Dim g As Graphics = Graphics.FromHwnd(Me.Handle)
Dim backbrush As SolidBrush = New SolidBrush(Color.Red)
g.FillRectangle(backbrush, rect)
backbrush.Dispose()
g.Dispose()


请高手指教!
__________________________________________________________________________
刚才的问题解决了,还想问一下,当check失败时,用e.Cancel = True返回到当前cell,如何能够选中当前cell里的值,想textbox的selectall方法?
__________________________________________________________________________
不是吧,这个论坛怎么连个强人都没有。
__________________________________________________________________________
还有个问题:
在CellValidating事件中,用 e.Cancel = True让焦点不跳出当前cell,并且用
Me.EditingControl.BackColor =
让当前cell的背景变颜色,但是,变颜色只是cell中间的一部分变了,还有很宽的一部分还是以前的颜色。谁知道还有其他办法吗?
__________________________________________________________________________
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值