I have a C# application that uses SpreadsheetGear's WorkbookView control. A user wants to be able to have changes he makes to comments on a cell saved.
Does anyone know of a way to capture changes when a user edits a comment. The cell edit events are not fired when a comment is edited and I can not find any way to capture changes a user makes to comments.
Before I read Joe's reply not knowing of a way to save comments individually, I decided to save comments by looping through the cells in a workbookView and grabbing the comments as the form is closing.
After seeing his reply, I found a way to get a comment right after it is entered using a combination of the workbookView1_ShapeSelectionChanged and workbookView1_ShapeAction events. The workbookView1_ShapeSelectionChanged event fires when the comment box is opened for editing and when the comment box is closed for editing. When it fires for the comment box opening, I get the ActiveCell because it may no longer be the ActiveCell when the comment box closes. I use that cell for getting the comment when the comment box closes if a comment has changed. The workbookView1_ShapeAction event fires everytime a new character is entered in the comment box which is useful for marking the comment as changed. After the comment is saved, the commentChanged variable is set back to false. Here is the code using the code that Joe posted in his answer:
private void workbookView1_ShapeAction(object sender, SpreadsheetGear.Windows.Forms.ShapeActionEventArgs e)
{
switch (e.ShapeActionType)
{
case SpreadsheetGear.Windows.Forms.ShapeActionType.TextChanged:
if (e.Shape.Type == SpreadsheetGear.Shapes.ShapeType.Comment)
{
//set comment changed flag to true
_commentChanged = true;
}
break;
}
}
private void workbookView1_ShapeSelectionChanged(object sender, SpreadsheetGear.Windows.Forms.ShapeSelectionChangedEventArgs e)
{
if (_commentChanged)
{
//get comment
string comment = _commentCell.Comment.Shape.TextFrame.Characters.Text;
//save comment
//....
//set comment changed flag to false
_commentChanged = false;
}
else
{
//get the cell whose comment is being edited
_commentCell = workbookView1.ActiveCell;
}
}