AD
Administrator
Syncfusion Team
December 9, 2004 11:56 AM UTC
Hi Angela,
look for the CurrentRecordContextChange event.
The e.Action will give information about the reason why the event was raised.
It can be one of
///
/// Specifies how the current record context changes.
///
///
/// This enum is used by the property
/// of the class.
public enum CurrentRecordAction
{
///
/// was called. You can cancel this operation by
/// setting the Cancel property.
///
BeginEditCalled,
///
/// is complete and returns.
///
BeginEditComplete,
///
/// was called. You can cancel this operation by
/// setting the Cancel property.
///
EndEditCalled,
///
/// is complete and returns.
///
EndEditComplete,
///
/// was called. You can cancel this operation by
/// setting the Cancel property.
///
CancelEditCalled,
///
/// is complete and returns.
///
CancelEditComplete,
///
/// was called. You can cancel this operation by
/// setting the Cancel property.
///
NavigateCalled,
///
/// is complete and returns.
///
NavigateComplete,
///
/// was called. You can cancel this operation by
/// setting the Cancel property.
///
LeaveRecordCalled,
///
/// is complete and returns.
///
LeaveRecordComplete,
///
/// was called. You can cancel this operation by
/// setting the Cancel property.
///
EnterRecordCalled,
///
/// is complete and returns.
///
EnterRecordComplete,
CurrentFieldChanged
}
When the user starts modifying a cell in the current record, e.Action will be BeginEditCalled
When the user has pressed Enter then e.Action will be EndEditCalled. You can cancel this operation by setting e.Cancel.
You can check if the record is the AddNewRecord with "e.Record is AddNewRecord".
Stefan
AD
Administrator
Syncfusion Team
March 12, 2005 04:37 PM UTC
this is the scenario i am facing.
at new row of ggc, i want to detect if the value entered in a cell is duplicate in another row. if it is, i want to cancel the action of adding that new row. i tried detecting the event on GridGroupingControlJobFunctions_CurrentRecordContextChange, setting e.cancel = true on e.action = EndEditCalled did not work.
where did i go wrong?
AD
Administrator
Syncfusion Team
March 13, 2005 10:14 AM UTC
Here is a TableControlCurrrentCellValidating event handler that will not let your user leave a cell in the AddNew row if he enters something that is already in an existing row. Will this serve your needs?
private void gridGroupingControl1_TableControlCurrentCellValidating(object sender,
GridTableControlCancelEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.Model[cc.RowIndex, cc.ColIndex];
if(style.TableCellIdentity.TableCellType == GridTableCellType.AddNewRecordFieldCell)
{
string colName = style.TableCellIdentity.Column.MappingName;
object newValue = cc.Renderer.ControlValue;
foreach(Record r in e.TableControl.Table.Records)
{
if(r.GetValue(colName).Equals(newValue))
{
//duplicate found
e.Inner.Cancel = true;
}
}
}
}
AD
Administrator
Syncfusion Team
March 30, 2005 07:13 PM UTC
the sample codes work if the check is performed on a single column. what if i want to perform it on 2 columns. ensuring column 1 do not have duplicate, and column 2 cannot be empty?
AD
Administrator
Syncfusion Team
March 31, 2005 12:28 AM UTC
If you need to check multipe columns you should handle the CurrentRecordContextChange event.
Example:
private void gridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)
{
Record r = e.Record as Record;
if (r != null && e.Action == CurrentRecordAction.EndEditCalled)
{
try
{
object id = r.GetValue("CategoryID");
if (id is DBNull || (int) id > 4)
{
object desc = r.GetValue("Description");
if (desc is DBNull || desc.ToString() == "")
{
e.Cancel = true;
MessageBox.Show("Error: Category > 10 or Categort null and Description empty");
}
}
}
catch (Exception ex)
{
e.Cancel = true;
MessageBox.Show(ex.Message);
}
}
}
You can download a sample project here:
CS.zip
Stefan
>the sample codes work if the check is performed on a single column. what if i want to perform it on 2 columns. ensuring column 1 do not have duplicate, and column 2 cannot be empty?
AD
Administrator
Syncfusion Team
March 31, 2005 03:23 PM UTC
i tried running the demo scripts. but it still allow me to go to the next record.
this is what i did:
1. i cleared the description field for id = 6.
2. hit enter
3. click [ok] for the prompt
4. hit down arrow key.
AD
Administrator
Syncfusion Team
March 31, 2005 04:41 PM UTC
To catch the use of the navigation keys, check for NavigateCalled as well as EndEditCalled in the event handler.
if (r != null &&
(e.Action == CurrentRecordAction.EndEditCalled
|| e.Action == CurrentRecordAction.NavigateCalled))
{
AD
Administrator
Syncfusion Team
March 31, 2005 08:42 PM UTC
I see what you mean. That should not happen when you set e.Cancel = true. It is limited to navigation with arrow keys.
We will get that fixed in our codebase.
Stefan
>To catch the use of the navigation keys, check for NavigateCalled as well as EndEditCalled in the event handler.
>
>
>
>if (r != null &&
> (e.Action == CurrentRecordAction.EndEditCalled
> || e.Action == CurrentRecordAction.NavigateCalled))
>{
>
AD
Administrator
Syncfusion Team
April 2, 2005 03:14 PM UTC
i tried using clay''s proposed solution. it''s still not working...
how do i obtain the fix to the codebase for this?
AD
Administrator
Syncfusion Team
April 2, 2005 04:02 PM UTC
Here is the sample above. Using 3.0.1.0 and following the steps you listed, I cannot leave the row either with the keyboard or the mouse. Can you?
http://www.syncfusion.com/Support/user/uploads/forum_Grouping_Validate_31a06ee.zip
There is a public release being finalized now, but I do not know when it will be uploaded, and am not sure that a fix for this problem made it into this release or not.
AD
Administrator
Syncfusion Team
April 3, 2005 02:53 AM UTC
i tried and i am still able to reproduce the bug. this is what i did.
1. click on description cell of id = 6
2. clear the content
3. hit down arrow key
4. click ok for the prompt.
i really hope it can make it into this release as i don''t want to resort to using a popup form to perform my validations.
for now as it seems, the only way out is to use this popup form for creating/updating records.
AD
Administrator
Syncfusion Team
April 3, 2005 08:33 AM UTC
Yes, this change has made it into the upcoming release.
In that release, checking on CurrentRecordAction.EndEditCalled and cancelling there prevents you from leaving the cell either using teh keyboard or the mouse.
AD
Administrator
Syncfusion Team
April 7, 2005 02:44 PM UTC
i downloaded 3.2.0.0. but it seem that i am still able to leave the record.
my codes look like this:
Private Sub GridGroupingControlEducations_CurrentRecordContextChange(ByVal sender As Object, ByVal e As Syncfusion.Grouping.CurrentRecordContextChangeEventArgs) Handles GridGroupingControlEducations.CurrentRecordContextChange
Dim rec As Syncfusion.Grouping.Record = e.Record
If Not rec Is Nothing AndAlso (e.Action = Syncfusion.Grouping.CurrentRecordAction.EndEditComplete) Then
Try
If rec.GetValue("Education") Is DBNull.Value OrElse rec.GetValue("EducationLevel") Is DBNull.Value Then
e.Cancel = True
End If
Catch ex As Exception
e.Cancel = True
End Try
End If
End Sub
AD
Administrator
Syncfusion Team
April 7, 2005 04:18 PM UTC
Try EndEditCalled instead of EndEditComplete.
AD
Administrator
Syncfusion Team
April 7, 2005 04:35 PM UTC
i tried changing from EndEditComplete to EndEditCalled. it appears that hitting the arrow keys now work the way it is suppose to be. but hitting enter will still cause the row to be inserted.
sorting the column will also cause the row to be added.
AD
Administrator
Syncfusion Team
April 8, 2005 09:48 PM UTC
Hi Lance,
we''ll have the Sort and Enter-Key behavior be fixed for the 3.2.1 build which we will get out next week.
Thanks for the patience.
Stefan
>i tried changing from EndEditComplete to EndEditCalled. it appears that hitting the arrow keys now work the way it is suppose to be. but hitting enter will still cause the row to be inserted.
>
>sorting the column will also cause the row to be added.
KE
Ken
April 25, 2005 07:02 PM UTC
Hi,
Where can I get the 3.2.1 build ?
>Hi Lance,
>
>we''ll have the Sort and Enter-Key behavior be fixed for the 3.2.1 build which we will get out next week.
>
>Thanks for the patience.
>
>Stefan
>
>>i tried changing from EndEditComplete to EndEditCalled. it appears that hitting the arrow keys now work the way it is suppose to be. but hitting enter will still cause the row to be inserted.
>>
>>sorting the column will also cause the row to be added.
AD
Administrator
Syncfusion Team
April 28, 2005 12:46 AM UTC
Essential Studio version 3.2.1.0 (final version of 3.2) is now available for download. You can download it from Direct-Trac (or use this link - http://www.syncfusion.com/squiffler/patches/v3.2.1.0/syncfusionessentialstudiosetup.exe).
Stefan