Home › Forums › WinForms controls › Xceed Grid for WinForms › Insertionrow cancel
-
AuthorPosts
-
#17045 |
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?
vb.net please
Thanks in advance.
Imported from legacy forums. Posted by troy@querytool.com (had 2161 views)
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
Next insertionCellAddHandler insertionRow1.EditCanceled, AddressOf insertionRow1_EditCanceled
values = New Dictionary(Of String, Object)(0)
End SubPrivate Sub insertionCell_LeavingEdit(ByVal sender As Object, ByVal e As LeavingEditEventArgs)
Dim cell As InsertionCell = TryCast(sender, InsertionCell)
If cell IsNot Nothing Then
values.Add(cell.FieldName, e.NewValue)
End If
End SubPrivate Sub insertionRow1_EditCanceled(ByVal sender As Object, ByVal e As EventArgs)
Dim insertionRow As InsertionRow = TryCast(sender, InsertionRow)
Dim value As ObjectIf 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
End If
Next fieldName
End Ifvalues.Clear()
End SubImported from legacy forums. Posted by André (had 438 views)
When I tryed this, after restoring the values (which worked) when I clicked on a different cell in the insertion row, the cell value became empty – and looks like the cells value is Nothing.
Any ideas?
Imported from legacy forums. Posted by troy@querytool.com (had 1721 views)
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.
e.g.:
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)
-
AuthorPosts
- You must be logged in to reply to this topic.