Constraint Exception Handling with C1 DataObjects

  • Thread starter Thread starter lgbjr
  • Start date Start date
L

lgbjr

Hi All,

I've posted this question on the ComponentOne news group, but I thought it
couldn't hurt to post it here as well, since, I’m assuming, some others out
there are using the C1 controls for VB.NET.
This is what I have:

VB.Net form with a c1FlexGrid and some c1Textboxes
C1ExpressConnection to an Access DB
C1ExpressTable
C1dbNavigator
The C1FlexGrid and C1textboxes are bound to the C1expresstable
Column3 (in the C1expresstable is a unique index, calculated with the
expression [column1]+'-'+[column2].

So far, this all works. When a new row is added, the user enters data in the
textbox bound to column1, then column2 and the calculation expression fills
column3. However, if the calculation produces a non-unique value for
column3, an error (Constraint Exception) is produced. The error is not
actually the problem (since I expect the error). My problem is figuring out
how to catch the error, so that I can show my own error message, clear the
current values in Col1, Col2, and Col3, and set the focus back to the
textbox bound
to column1. Does that make sense?

I've looked through the docs and tutorials and found enough to know that I
can catch the error and do what I want to do. Unfortunately, I didn't find
enough information (or an example) to actually implement the solution.

All help and comments will be greatly appreciated!!

Thanks
Lee
 
Hi

When the error, did it popup an error dialog?
If so, I think the ComponentOne has handle the error inside the control.
Since we have no the source code how about they implement the control, so
I think the component one support website would be the correct place.

Thanks for you understanding.

If you still have any concern please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Peter,

Yes, there is an error dialog that basically says the value the user is
trying to add to the column is not unique (since the column is the Primary
Key). I expect this error to occur. But, I want to catch the error and use
my own error dialog (which will be a bit less cryptic and give the user a
choice to cancel the new row, or re-enter a unique value). Unfortunately,
the C1 website has little to offer, other than a copy of the help files,
which are not very clear.

The reason I decided to post here to begin with was that I was hoping that
since C1 and Microsoft had a deal with the VB Resource Kit and C1 Studio.Net
that there would be enough other people on this list using the C1
components.

the C1 documentation makes it clear that this type of exception can be
handled, but it doesn't say which ErrorEventHandler to use, and I've tried
just about every combination to see which handler catches this constraint
exception (with no luck!)

I've posted the same info on the C1.Data Newsgroup, so we'll see who wins
the prize by providing me with the answer first!

Regards,
Lee
 
Hi

I am not familar with the c1FlexGrid.
Basically as a common control in vs.net, e.g. TextBox, it has validate
event which will be raised after the focus is lost. And then we can handle
our validate method in the event handler, e.g. throw an exception or just
pop up a msgbox. I think the c1FlexGrid may use the similar approach, while
since it pop up a msgbox which is not an exception. If we do not handle an
exception, the exception will be thrown up through the call stack until the
program crash if we did not handle it in any place in the program. While a
msgbox if just a message, it is similar with the code below.
validate_handle
{
if(notvalid)
msgbox "something is wrong";
}

So in this way we have no idea about that the validate_handle failed.
So the problem depends on how the validate_handle is implemented, e.g.
will it raise another errorevent or something else to give the user a
chance to handle?

Hope this helps.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Peter,

I've got the error handling stuff worked out. I finally got email from C1
and they told me which error handler would capture this particular event.
the particular handler that they use, by name, didn't seem to be the right
choice, so I never even tried it.

Anyway, I'm intercepting the exception, displaying my own message, and going
on from there. But I discovered another small issue. Maybe you can shed some
light on it for me.

As I mentioned before, I have textboxes that are bound to various columns in
a table. TB1 goes to Column1, TB2 to Column2, etc. And the Primary key is
Column3. There is a calculation in the table that combines the vales of
Column1 and Column2. If the user enters a value in TB1, then TB2 and the
calculation produces a non-unique value for Column3, the exception is
thrown. The user has a choice from the message box to re-enter the values in
TB1 and TB2, or just cancel the new entry.

Here's the problem. Let's say the user decides to cancel. What I do is call
a Fill on the Connection, which updates the table. This wipes out the new
row the user was tring to add and displays the values from the last row of
data in the textboxes on the form. Or, at least, this is what is supposed to
happen! For some reason, the value in TB2 (the textbox that had focus just
before the exception occured) retains the value the user entered. The table
however does not have this value, only the textbox. All of the other
textboxes are updated correctly with the contents of the current row of the
table. As a quick test, I added a new row, entered a value in TB2 first,
then in TB1 (the values intentionally caused a Primary Key exception). In
this case, the value in TB2 is correct, but the value in TB1 remains
unchanged.

In my error event code, I have even added TB2.Text="" (or any text), but the
value that was typed into the textbox remains, even after the table has been
re-filled. If I use the record navigator to move to the previous record,
then back, the textbox is fine.

This same behavior occurs whether I use a VB.NET textbox or a C1Textbox. Do
you have any idea what might cause this behavior?

Regards,
Lee
 
Hi

I think you may try to write the databinding and fill code in a function,
and then call it from the form_load and other place you want to refresh the
databing to the database to see if the problem persists.
You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top