Accessing a Cell Change event

Jun 22, 2012 at 6:25 PM

Is there any event that I can get that will tell me if a cell's contents changed?  If so, how do I get it.

I have no problem doing a  event += delegate construct, but I just do not know what the name is and where it is.

Thanks in advance

Jun 25, 2012 at 1:22 AM

Have you looked at onvaluechanged?  I have a project that required that if certain cell contents changed, other fields needed to be updated.  I created a controller which included an override for onvaluechanged.  The purpose for the override was to determine which cell had changed and what should be done.

If you have a code example, I can look at it.

Jun 25, 2012 at 1:36 AM

Also look at examples 26 and 51.  Good luck.

Jun 26, 2012 at 3:29 PM

If I go to the GUI design area there is no OnValueChanged, at least not that I saw.

If I go to the code and going "grid.", the popup shows only 'ClipboardUseOnlyActivatePosition, OnCellsAreaChanged, OnUserException, and ScrollOnPaint' methods and properties, but no events to tap into.

1. What is complete path to the OnValueChanged eevent?

2. Where are the examples?  What is the complete path to them and if part of the source download, where in the tree?

Thanks in advance,

Sarah

Coordinator
Jun 27, 2012 at 9:42 AM

Hi Sweinberger,

For OnValueChanged event example look at frmSample26. You can find it by searching for the class with name 'frmSample26'.

Source code is here: https://bitbucket.org/dariusdamalakas/sourcegrid

 

Jun 27, 2012 at 12:25 PM

Sweinberger,

The samples are in the code tree.

Here is the path to the example based on my installation: C:\Documents and Settings\. . . . . . .\My Documents\Visual Studio 2008\Projects\dariusdamalakas-sourcegrid-c161edf8501f\SourceGrid.Examples\GridSamples\StandardFeatures

Joe

Jun 27, 2012 at 2:52 PM
Edited Jun 27, 2012 at 3:19 PM

Hello,

Sample 26 has a problem in my implementation.  I have the following construct, which has the error on CellChanged

"Cannot access a non-static member of outer type 'Whatever.Spread' via a nested type 'Whatever.Spread.ValueChangedEvent'.

Implementing the cell changed event, as mentioned in Sample 26 causes the issue that I cannot fire off the event to the caller.

By the way, in the folder, there is no frmSample51.cs.  That folder has the following sample numbers:

3, 17, 19, 21, 21Events, 24, 26, 56, 57, and 61.  Do you mean 61?

Thanks,

Sarah

namespace Whatever
{
	public partial class Spread : UserControl
	{
		public delegate void CellChangedHandler(object sender, SpreadCellChangedEventArgs e);

		public event CellChangedHandler CellChanged;

		public Spread()
		{
			InitializeComponent();

			this.ctlTable.Controller.AddController(new ValueChangedEvent());
		}

		public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
		{
			public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
			{
				base.OnValueChanged(sender, e);

				// Raise of the event.
==> Causes error				if (null != CellChanged)
				{
					// 
				}

				//string val = "Value of cell {0} is '{1}'";

				//MessageBox.Show(sender.Grid, string.Format(val, sender.Position, sender.Value));
			}
		}

		public class SpreadCellChangedEventArgs : EventArgs
		{
			private int m_iCol, m_iRow;

			public SpreadCellChangedEventArgs(int iRow, int iCol)
			{
				this.m_iCol = iCol;
				this.m_iRow = iRow;
			}

			public int Row
			{
				get { return this.m_iRow; }
			}

			public int Column
			{
				get { return this.m_iCol; }
			}
		}
	}
}
Jun 27, 2012 at 3:52 PM

Hello,

When you say you have a problem in your implementation, are you meaning your code or in the example.

If you downloaded the source and built the project, you should have WindowsFormsSample.exe in:

C:\Documents and Settings\. . . . .\My Documents\Visual Studio 2008\Projects\dariusdamalakas-sourcegrid-c161edf8501f\SourceGrid.Examples\bin\Debug.

Run the program and select Sample #26 under Standard Features. If you change a value in the ‘Value Changed’ you will get a message box dialog when you leave the cell.

Is this what you are looking to do?

Joe

From: sweinberger [email removed]
Sent: Wednesday, June 27, 2012 8:53 AM
To: joemohr@montanamail.us
Subject: Re: Accessing a Cell Change event [sourcegrid:360631]

From: sweinberger

Hello,

Sample 26 has a problem in my implementation. I have the following construct, which has the error on CellChanged

"Cannot access a non-static member of outer type 'Whatever.Spread' via a nested type 'Whatever.Spread.ValueChangedEvent'.

Implementing the cell changed event, as mentioned in Sample 26 causes the issue that I cannot fire off the event to the caller.

namespace Whatever
{
public partial class Spread : UserControl
{
public delegate void CellChangedHandler(object sender, SpreadCellChangedEventArgs e);

public event CellChangedHandler CellChanged;

public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
{
public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
{
base.OnValueChanged(sender, e);

// Raise of the event.
==> Causes error if (null != CellChanged)
{
//
}

//string val = "Value of cell {0} is '{1}'";

//MessageBox.Show(sender.Grid, string.Format(val, sender.Position, sender.Value));
}
}

public class SpreadCellChangedEventArgs : EventArgs
{
private int m_iCol, m_iRow;

public SpreadCellChangedEventArgs(int iRow, int iCol)
{
this.m_iCol = iCol;
this.m_iRow = iRow;
}

public int Row
{
get { return this.m_iRow; }
}

public int Column
{
get { return this.m_iCol; }
}
}
}
}

Thanks,

Sarah

Jun 27, 2012 at 4:30 PM

Hi Joe,

I thought that I made it clear, especially rewriting the error message.

The specific coding error is:

// Raise of the event.
if (null != CellChanged)

With the error being

"Cannot access a non-static member of outer type 'Whatever.Spread' via a nested type 'Whatever.Spread.ValueChangedEvent'.

CellChanged gets a wavy red line.  I want to pass on the event, but that is not possible.

Rebuilding the sample code does not apply to this specific error.  I cannot raise the event.

Simply put, how do I raise the event, considering that VS throws an error coding "if null != CellChanged"?

Regards,

Sarah

Jun 27, 2012 at 5:53 PM

Hi,

Just to be sure I understand, you are trying to raise the CellChanged event. Is that correct? Is that to force OnValueChanged?

Thanks!

I will be out for a while and will get back to you when I can.

Joe

From: sweinberger [email removed]
Sent: Wednesday, June 27, 2012 10:31 AM
To: joemohr@montanamail.us
Subject: Re: Accessing a Cell Change event [sourcegrid:360631]

From: sweinberger

Hi Joe,

I thought that I made it clear, especially rewriting the error message.

The specific coding error is:

// Raise of the event.
if (null != CellChanged)

With the error being

"Cannot access a non-static member of outer type 'Whatever.Spread' via a nested type 'Whatever.Spread.ValueChangedEvent'.

CellChanged gets a wavy red line. I want to pass on the event, but that is not possible.

Rebuilding the sample code does not apply to this specific error. I cannot raise the event.

Simply put, how do I raise the event, considering that VS throws an error coding "if null != CellChanged"?

Regards,

Sarah

Jun 27, 2012 at 6:08 PM

Hi,

Yes/No.  Yes, I want to raise the CellChanged event, but not to force OnValueChanged.  On ValueChanged gets called, whenver a cell value gets changed.  I receive that value, if coded properly above, notification from that some cell changed in that event.  I then raise my custom CellChanged event from within that event.

Raising the event exposes to the outside world that a cell's contents changed.

I am creating a custom spreadsheet control that encapsulates the spreadsheet grid control.  In order to raise the CellChanged event, I need to be able to call it from the grid cell changed event handler, but that is not possible, because of the error shown.

Sarah

Jun 27, 2012 at 11:04 PM

Hello again,

I think this might address your issue.

http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/e3449b4f-ea65-4510-80fd-5f24ef4e486a

Joe

From: sweinberger [email removed]
Sent: Wednesday, June 27, 2012 12:09 PM
To: joemohr@montanamail.us
Subject: Re: Accessing a Cell Change event [sourcegrid:360631]

From: sweinberger

Hi,

Yes/No. Yes, I want to raise the CellChanged event, but not to force OnValueChanged. On ValueChanged gets called, whenver a cell value gets changed. I receive that value, if coded properly above, notification from that some cell changed in that event. I then raise my custom CellChanged event from within that event.

Raising the event exposes to the outside world that a cell's contents changed.

I am creating a custom spreadsheet control that encapsulates the spreadsheet grid control. In order to raise the CellChanged event, I need to be able to call it from the grid cell changed event handler, but that is not possible, because of the error shown.

Sarah

Jun 28, 2012 at 3:06 PM
Edited Jun 28, 2012 at 3:07 PM

Hello,

Adding in a static, although solving the immediate compiling issue, has the effect of the event not showing up in the GUI design editor within Visual Studio.

public event SelectionChangedHandler SelectionChanged;
public static event CellChangedHandler CellChanged;

The first line, SelectionChanged, shows up nicely, whereas the second line, "CellChanged" does not show up.
Let me restart, I need a way to get at and then forward the cell changed event.  The sample in this thread solves the first
part, although I have not tested that yet, but does not solve the second part, which is to be able to forward the event.

Sarah

Sarah

 

Jul 2, 2012 at 3:49 PM

Okay, I solved my own problem.  For those that might want the solution, here it is.

// In outer class constructor
this.ctlTable.Controller.AddController(new ValueChangedEvent(this));

...

// The embedded class.

public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
{
	// Member Variables
	Spread m_oSpread = null;

	public ValueChangedEvent(Spread oSpread)
	{
		// Save the main spread control argument.
		this.m_oSpread = oSpread;
	}

	public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
	{
		base.OnValueChanged(sender, e);

		// Raise of the event.
		if (null != this.m_oSpread.CellChanged)
			this.m_oSpread.CellChanged(this, new SpreadCellChangedEventArgs(sender.Position.Row, sender.Position.Column));
	}
}

Sarah