User (Old forums)MemberMay 4, 2009 at 8:55 pmPost count: 23064
If I want to cancel my insertionrow edit (maybe the db rejected the query because of primary key etc), can I cancel and keep the data that the user has already entered into the various cells of the insertionrow?
Thanks in advance.
Imported from legacy forums. Posted by email@example.com (had 2161 views)User (Old forums)MemberMay 5, 2009 at 4:12 pmPost count: 23064
You can use the LeavingEdit and EditCanceled events to save and then restore the values to the InsertionRow cells. Here is a basic implementation :
Private values As Dictionary(Of String, Object)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
For Each insertionCell As InsertionCell In insertionRow1.Cells
AddHandler insertionCell.LeavingEdit, AddressOf insertionCell_LeavingEdit
AddHandler insertionRow1.EditCanceled, AddressOf insertionRow1_EditCanceled
values = New Dictionary(Of String, Object)(0)
Private Sub insertionCell_LeavingEdit(ByVal sender As Object, ByVal e As LeavingEditEventArgs)
Dim cell As InsertionCell = TryCast(sender, InsertionCell)
If cell IsNot Nothing Then
Private Sub insertionRow1_EditCanceled(ByVal sender As Object, ByVal e As EventArgs)
Dim insertionRow As InsertionRow = TryCast(sender, InsertionRow)
Dim value As Object
If insertionRow IsNot Nothing Then
For Each fieldName As String In values.Keys
If values.TryGetValue(fieldName, value) Then
CType(insertionRow.Cells(fieldName), InsertionCell).IdleValue = value
Imported from legacy forums. Posted by André (had 438 views)User (Old forums)MemberMay 5, 2009 at 6:44 pmPost count: 23064User (Old forums)MemberMay 6, 2009 at 3:20 pmPost count: 23064
This was only a basic implementation, and you need to increment on it, so it works as you need in all scenarios. For example, once the InsertionRow enters edition, the IdleValue of insertion cells are discarded, and the underlying DataRow is created, so you need to set the Value property on each cell. To do this, you need to handle the EditBegun event on the InsertionRow.
void insertionRow1_EditBegun( object sender, EventArgs e )
InsertionRow insertionRow = sender as InsertionRow;
if( insertionRow != null )
foreach( InsertionCell cell in insertionRow.Cells )
if( cell.IdleValue != null )
cell.Value = cell.IdleValue;
Imported from legacy forums. Posted by André (had 2264 views)
- You must be logged in to reply to this topic.