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.
Syncfusion Feedback

Managing Event Reentrancy

Thread ID:

Created:

Updated:

Platform:

Replies:

8189 Oct 24,2003 10:47 PM UTC Oct 25,2003 12:52 PM UTC Windows Forms 2
loading
Tags: GridControl
Brent McCullough
Asked On October 24, 2003 10:47 PM UTC

First: Great product guys and gals! Thanks. Second: Help! Using an unbound grid control, I am trying to simulate the new record row found in most databound grids. I have a row basestyle that makes it behave right. When a cell in the row has valid data entered, I want to create a new new record row. I have trapped several events to try to do this; all end up with an exception: "Deactivate called while the current cell was in process of activating or deactivating a cell". I even tried spawning a new thread to Invoke back to the control, hoping that would cause all of the grid events to settle down before I tried to insert the row. Same result. So there are two questions here: Grid-specific: What event should I trap to accomplish this? .NET general: In Win32 SDK programming, we would just post a message and perform the work when the message returned. This not in the spirit of managed code (+ if I have to resort to this, why don't I just stay in C++, right?). Is there a recommended way in .NET to deal with this usage pattern? Thanks in advance.

Administrator [Syncfusion]
Replied On October 25, 2003 06:43 AM UTC

1) In most grid's that have this auto AddNew row, the row gets added as you type the first character on the last (or as the cell on the last row goes into edit mode). If you add the row at this point, you will not have this problem. So, this event handler will work.
private void gridControl1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.RowIndex == this.gridControl1.RowCount)
	{
		this.gridControl1.RowCount++;
		this.gridControl1[this.gridControl1.RowCount, 1].Text = "DefaultValue1";
		this.gridControl1[this.gridControl1.RowCount, 2].Text = "DefaultValue2";
	}
}
But if you want to add the new row as you end the editing on the first cell in the last row, you do run into this problem. In this case, you can avoid the problem by locking the currentcell as you add the row.
private void gridControl1_CurrentCellEditingComplete(object sender, System.EventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.RowIndex == this.gridControl1.RowCount)
	{
		cc.Lock();
		this.gridControl1.RowCount++;
		cc.Unlock();
		this.gridControl1[this.gridControl1.RowCount, 1].Text = "DefaultValue1";
		this.gridControl1[this.gridControl1.RowCount, 2].Text = "DefaultValue2";
	}
}
2) I don't have an answer for your second question. From our point of view, we want the set of events to be rich enough that there is an appropriate one available to allow you to do the tasks you need to get done. And, if we miss one, we will try to add it if at all reasonable/possible.

Brent McCullough
Replied On October 25, 2003 12:52 PM UTC

Works like a charm. Thank you very much.

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.

Warning Icon 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.Close Icon

;