
<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中間的一部分變了,還有很寬的一部分還是以前的顔色。誰知道還有其他辦法嗎?
__________________________________________________________________________