Accessing Comment Changes in a Spreadsheetgear WorkbookView Control - spreadsheetgear

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;
}
}

Unfortunately, the answer is "sort of but not really".
You can catch the ShapeAction event as demonstrated below, but the ShapeAction event is really designed for shapes and not for comments so you cannot get the current text (the text hsa not yet been stored in the shape) and you cannot even get the cell which the comment belongs to. Still, I will paste in some code since it might be of use to you:
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)
{
// Unfortunately, this is as far as we can get since IShape
// does not have a way to get back to the cell which owns the comment.
//
// Furthermore, the text is not yet stored in the IShape, so we
// cannot get the current text either.
}
break;
}
}
If you send email to support at SpreadsheetGear requesting this capability they will add this feature request to their list with your email address associated with it.

Related

TStringGrid doesn't recognize VK_DELETE as a keypress

I have a number of TStringGrids inside TTab's and have been using
if (Key==VK_RETURN) for years (its an old app) as the trigger to execute code pertaining the the cell entry.
I would now like the option to delete the Cell contents, by writing a empty string to it, so tried using
if (Key==VK_DELETE)
yet the Delete Button does not trigger the OnKeyPress event at all in my case.
I was hoping to capture the event via the following code pertaining to the specific active Stringrid1
void __fastcall TPagesDlgLoadEditorFixed::StringGrid1KeyPress(TObject
*Sender, char &Key)
{
int Grid = 1;
EntriesOnStringGrid(Key, Grid);
}
and with the KeyPress then passed on code that is common to all the StringGrids, as follows:
void TPagesDlgLoadEditorFixed::EntriesOnStringGrid(char &Key, int Grid)
{
if (Key==VK_RETURN)
{
//code works fine
}
if (Key==VK_DELETE)
{
//code has no effect
}
}
However whilst in debug mode, one can see that the StringGrid1KeyPress event is not triggered at all by the "Delete" button.
Any advise would be greatly appreciated.
It's generally better to use OnKeyUp and OnKeyDown when checking for virtual key codes instead of OnKeyPress.
So using that should fix your problem and then it will detect VK_DELETE when it's pressed or let go.

ListGrid put focus in the FilterEditor

I have a ListGrid defined like this:
ListGrid lgrid = new ListGrid();
ListGridField first = new ListGridField("first",first");
ListGridField second = new ListGridField("second ",second ");
lgrid.setFields(first, second);
lgrid.setShowFilterEditor(true);
¿How can i put the keyboard focus in the first filter editor field after i call show() in the layout?
Thxs in advance.
Depending on what your use case is (which would be useful to provide a more focused answer), the solution you posted might not be what you really need, because if you scroll on your ListGrid, it could trigger a new data fetch (if there are more records to show), and move the cursor to the filter editor as a result (if your user is editing some records at that point, the cursor moving to the filter row is not what she would want to happen!!).
In such a case, you probably just want to call grid.focusInFilterEditor("fieldToFocus") after the listGrid.show() statement or in the ClickHandler of some button you use to fetch the data, etc.
Anyway, you don't need the Timer either. This works:
listGrid.addDataArrivedHandler(new DataArrivedHandler() {
#Override
public void onDataArrived(DataArrivedEvent event) {
grid.focusInFilterEditor("fieldToFocus");
}
});
I got the solution, its focusInFilterEditor, this is an example to set the focus after the data arrived to the grid:
// Put the focus on the first listGrid field when is loaded
listGrid.addDataArrivedHandler(new DataArrivedHandler() {
#Override
public void onDataArrived(DataArrivedEvent event) {
Timer t = new Timer() {
public void run() {
if(listGrid.getFilterEditorCriteria() == null){
listGrid.focusInFilterEditor("fieldToFocus");
}
}
};
t.schedule(600);
}
});

Won't update UILabel from Parse data in swift

I am trying to update my UILabel to a String from my Parse database.
My problem is the label will not update my firstnameLabel when I first sign in. But it WILL update, when i sign in (nothing happens), push the stop button in Xcode and then launch it again (still logged in) and then it updates the label.
How can I do this faster??
Here is my code:
var currentUser = PFUser.currentUser()
if currentUser != nil {
var query = PFQuery(className:"_User")
query.getObjectInBackgroundWithId(currentUser.objectId) {
(bruger: PFObject!, error: NSError!) -> Void in
if error == nil && bruger != nil {
var firstName: String = bruger["firstname"] as String
self.usernameLabel.text = firstName
} else {
println("Error")
}
}
} else {
self.performSegueWithIdentifier("goto_login", sender: self)
}
Hope you can help me!
Rather than trying to load the user object again by the id, try just doing a fetch instead.
[currentUser fetchIfNeededInBackgroundWithBlock: ... ];
By trying to load the object, you might be getting a cached version.
I read somewhere that it could be because of the fact that the could was put inside the ViewDidLoad. I tried to put it outside of that and it worked!
It sounds like you put it in the ViewDidLoad method. You should put it in the ViewWillAppear method instead. Here's an example.
1) ViewDidLoad - Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms.
2) ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).
3) ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.

Touch Event Blackberry Triggered Multiple Times

I'm working with the Blackberry Touch Event and I need to process the TouchEvent.MOVE, TouchEvent.UP and TouchEvent.DOWN to move a carousel of images and the TouchEvent.CLICK to generate some specific action.
My problem is that the touchEvent() method is being called several times. How can I prevent this? Because the behaviour is getting all messed up.
For example: when I just want to capture the TouchEvent.CLICK event, the UP-DOWN-MOVE-CLICK are being triggered one after the next.
My code does the following:
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
//CHANGE THE CONTENT OF A FIELD
return true;
} else if ((message.getEvent() == TouchEvent.MOVE)
|| (message.getEvent() == TouchEvent.UP)
|| (message.getEvent() == TouchEvent.DOWN)) {
//DELETE THE FIELD
//MOVE A CAROUSEL OF IMAGES
} else {
return false;
}
}
public void moverTouch(int dx) {
//ADD THE FIELD PREVIOUSLY DELETED
}
As you can see, when the CLICK event is captured, I need to change the content of a field, but when the MOVE or UP or DOWN event is captured, I need to delete that Field from his manager, do some working with a carousel of images, and then re-add the field previously deleted.
The carousel moving part works fine, but when I try to capture JUST the CLICK event, and the others are being triggered as well, but the moverTouch() function doesn't get triggered because there is no actual movement on the carousel of images, I end up with a deleted field that I need to update its content.
At a glance:
I think you need to differentiate touch gestures (I believe you are "listening" for something like a swipe gesture to scroll the gallery image) from "normal" touch events (specifically you need to process TouchEvent.CLICK to apply "some specific action" to the clicked image).
To decide whether the TouchEvent represents a gesture there is a TouchEvent.GESTURE constant. Then it is possible to know what exactly TouchGesture it represents by calling TouchEvent.getGesture().
Some sample code for touch gestures can be viewed here.

Update a text field in BB OS 6 when a listener method is invoked

For the GUI portion of my app, how could I update the RichTextField when my batteryStatusChange method is invoked that changes on the spot?
I was thinking of calling a set method and then having RichTextField get that new number, but it will make a long list of lines unless I delete the textfield before I add a new one.
Something like the battery percentage number under Device Information or the signal strength that changes on the spot.
Edit: Figured it out using setText
public void batteryStatusChange(int status)
{
// TODO Auto-generated method stub
if ((status & DeviceInfo.BSTAT_LEVEL_CHANGED) != 0)
{
batteryStatusField.setText(getBatteryLevel());
}
}
batteryStatusField.setText(getBatteryLevel());
public String getBatteryLevel() {
return Integer.toString(DeviceInfo.getBatteryLevel()) + " %";
}
Got it to work with this code above by putting it inside my batteryStatusChange listener function. Later I will add in more parameters after the function getBatteryLevel() to keep my default formatting.
My battery app in progress

Resources