Posted 21 January 2018, 9:10 pm EST
Hello,
Can we attach the new Expression Editor for c1TrueDBGrid.
Thanks
Richard
Forums Home / ComponentOne / WinForms Edition
Posted by: grapecity on 21 January 2018, 9:10 pm EST
Posted 21 January 2018, 9:10 pm EST
Hello,
Can we attach the new Expression Editor for c1TrueDBGrid.
Thanks
Richard
Posted 23 January 2018, 8:27 am EST
Hello,
To attach C1ExpressionEditor to the C1TrueDBGrid you need to perform the following steps:
set C1TrueDBGrid.DataSource (and DataMember if needed) - C1ExpressionEditor warks only in bound mode;
add unbound column to grid, for example “Total” or add expression column to the DataSource.
Note: in first case you cannot use filtering for the expression column, because filtering in C1TrueDBGrid works only with bound column.
set expression:
c1TrueDBGrid1.Columns[“Total”].Expression = “[Price] * [Quantity]”
you can also set AllowExpressionEditing property to allow user to edit the expression at run time by clicking the expression icon in the column header:
c1TrueDBGrid1.Splits[0].DisplayColumns[“Total”].AllowExpressionEditing = true;
And most importantly, make sure that C1.Win.ExpresionEditor.dll is presented in the project references. When you change the properties associated with the ExpressionEditor in the design time, then ExpresionEditor.dll will be attached to references automaticaly. Otherwise, you should attach it manually.
Also, you can see an example of integration in C1ExpressionEditor\TrueDBGridIntegration sample.
Thanks,
Nikita Parkhomenko
WinForms Developer
GrapeCity, Inc.
Posted 23 January 2018, 11:08 pm EST
Hi Nikita,
I tried your suggestion and it works!
Additional query, how do I capture the error when the user entered an invalid expression. I tried the c1TrueDBGrid.Error += event handler but to no avail.
Richard
Posted 24 January 2018, 3:32 am EST
Hi Richard!
Currently, there is no direct way to achieve this behaviour in this integrated ExpressionEditor control.
Can you please let us know the use case, so that we can see if anything can be done in this regard.
Best regards,
Meenakshi
Posted 28 January 2018, 7:32 am EST
Hi Meenakshi,
At runtime when the user entered an invalid expression, my winform application crashers with this message “An unhandled exception of type ‘System.NullReferenceException’ occurred in C1.Win.C1TrueDBGrid.4.dll”
I just want to catch this error using try and catch error handling.
Thanks.
Richard
Posted 29 January 2018, 4:53 am EST
Hi Richard,
This is a bug, there should be no exceptions while user working with expression. I remember something like that. It has been fixed in recent updates. And i couldn’t reproduce this in the last build 4.0.20173.291.
Do you have the opportunity to upgrade to a latest version?
It will be the best solution. But even if you for some reason can’t upgrade to the latest version, I still can offer you workaround to handle this exception:
inherit C1TrueDrueDBGrid and override OnClick method something like this:
public class C1TrueDBGridEx : C1TrueDBGrid
{
// ExpressionEditor form is opened and processed during the Click event
// So to catch this exception you need here
protected override void OnClick(EventArgs e)
{
try
{
// you may need to backup the previous value of the
// Column.Expression property before this
base.OnClick(e);
}
catch(Exception)
{
// exception handler
// restore old expression
}
}
}
and use this instead of C1TrueDBGrid.
But it’s not the best solution and I strongly recommend you to upgrade to the latest version.
Hope this will help you.
Thanks,
Nikita Parkhomenko
WinForms Developer
GrapeCity, Inc.
Posted 30 January 2018, 3:19 am EST
Hi Nikita,
Thanks for the quick reply. Will try your suggestion.
Thanks again.
Richard