We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Exception from RowChanging. How to catch?

Thread ID:

Created:

Updated:

Platform:

Replies:

58111 Mar 19,2007 09:24 AM Mar 21,2007 06:54 AM Windows Forms 4
loading
Tags: GridControl
c4p
Asked On March 19, 2007 09:24 AM

Hello all!
I have special class called ConnectedDataTable.
It's a child of DataTable.
In RowChanging and RowDeleting events it throws an exception. But my GridDataBoundGrid doesn't catch it. How can I catch such exception?

Administrator [Syncfusion]
Replied On March 19, 2007 12:51 PM

Hi c4p,

Please try to provide us some more information on this issue. I tried to reproduce the issue, but couldn't. kindly provide us a small sample to reproduce the issue or modify the browser sample accordingly. This will help us to analyse the issue further.

Best Regards,
Haneef

c4p
Replied On March 20, 2007 03:07 AM

Hello!
Thanks for the reply.

I've reconstructed my problem in short code fragment:
1. Create Windows Froms Application.
2. Add GridDataBoundGrid to the form.
3. Add this code:

private DataTable myTable;
private void Form1_Load(object sender, System.EventArgs e)
{
myTable = new DataTable("Hello");
myTable.Columns.Add("SomeCol", typeof(String));

myTable.RowDeleting += new DataRowChangeEventHandler(myTable_RowDeleting);

gridDataBoundGrid1.DataSource = myTable;
}

private void myTable_RowDeleting(object sender, DataRowChangeEventArgs e)
{
throw (new Exception("Some text."));
}

Then, after adding rows I trying to delete row and get unhandled exception. How can I catch this exception?

My Platform: .Net 1.1, Syncfusion 4.1.0.62.

Administrator [Syncfusion]
Replied On March 20, 2007 06:35 PM

Hi C4p,

The reason for getting this exception is that you are throwing the exception (throw (new Exception("Some text."));) in RowDeleting event. If you want to handle the exception then use the Try...Catch block statement in a RowDeleting event. Here is a code snippet.

private void myTable_RowDeleting(object sender, DataRowChangeEventArgs e)
{
try
{
throw (new Exception("Some text."));
}
Catch(Exception ex)
{
Console.WriteLine("User thrown the Exception in RowDeleting event");
}
}


Best regards,
Haneef

c4p
Replied On March 21, 2007 06:54 AM

Hello Haneef.
It not that I really need. I need that control catch the exception and warn the user about it. I can't catch inside RowDeleting event.

I found the solution for deleting rows:

private void grid_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
GridRangeInfoList rangeList = this.grid.Selections.GetSelectedRows(true, false);

if(rangeList.Count <= 0)
return;

ArrayList a = new ArrayList();
CurrencyManager cm = (CurrencyManager)this.grid.BindingContext[this.grid.DataSource, this.grid.DataMember];

foreach(GridRangeInfo range in rangeList)
{
for(int row = range.Top; row <= range.Bottom; ++row)
{
int pos = this.grid.Binder.RowIndexToPosition(row);
a.Add(-pos);
}
}

a.Sort();
foreach(int pos in a)
{
try
{
cm.List.RemoveAt(-pos);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
e.Cancel = true;
}

But how can I create and edit rows in DataTable from RowEditing event in the same manner?

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;