![VB.NET源码-156个实用实例哦……](http://www.zhzx123.com/VB.NET_03.gif)
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中间的一部分变了,还有很宽的一部分还是以前的颜色。谁知道还有其他办法吗?
__________________________________________________________________________