翻譯|其它|編輯:郝浩|2004-01-12 21:04:00.000|閱讀 1423 次
概述:
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
如果綁定了datagrid,在datagrid中對(duì)數(shù)據(jù)進(jìn)行更改后,點(diǎn)擊窗體中的toolbar按鈕進(jìn)行保存時(shí),最后輸入的那個(gè)數(shù)據(jù),如果焦點(diǎn)沒有移開,在保存的時(shí)候就得不到提交,只有移開焦點(diǎn)的時(shí)候才能提交!
在csdn的貼子上搜索了很久,發(fā)現(xiàn)很多人都是建議不用toolbar,而是用button控件,網(wǎng)友covis的解釋是“用帶SELECTED屬性的控件提交數(shù)據(jù)即可。可能你用TOOLBAR的按鈕或其它沒有SELECTED屬性的控件提交數(shù)據(jù)的。因?yàn)樗荒鼙贿x中,所以他不能接受焦點(diǎn),一般的按鈕或控件可以將其它控件的焦點(diǎn)轉(zhuǎn)移到自己身上。從這里去考慮。”原文在://search.csdn.net/expert/topic/52/5201/2003/4/21/1688615.htm
但是由于筆者所有的toolbar都已經(jīng)做好了,再更改起來麻煩也不美觀,能不能找到其它方法來實(shí)現(xiàn)呢?
經(jīng)過一些摸索,發(fā)現(xiàn)了如下的方法可以實(shí)現(xiàn):
Public Sub SaveData()
'檢查當(dāng)前焦點(diǎn)是否在datagrid上,是就切換單元格,并提交更改。
If Me.ActiveControl.Parent.GetType Is GetType(DataGrid) Then
Dim dg As DataGrid = CType(Me.ActiveControl.Parent, DataGrid)
ChangeCurrentCell(dg)
Me.BindingContext(dg.DataSource).EndCurrentEdit()
End If
.....save代碼
End Sub
Public Function ChangeCurrentCell(ByVal dg As DataGrid) As Boolean
Try
Dim temp As DataGridCell = dg.CurrentCell
dg.CurrentCell = New DataGridCell(temp.RowNumber, 0)
dg.CurrentCell = temp
Return True
Catch ex As Exception
Return False
End Try
End Function
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn