Spreadsheet gear cell with list validation selection changed event? - spreadsheetgear

I have list validation on a few cells and would like to shade the cell if a value is selected/changed from dropdown(filter list). For regular cells, I use EndEdit event which apparently doesn't fire in this case.
Could anyone please point me to right event to do this?
Thanks in advance!

There is no specific event that fires for a cell validation dropdown selection action. The WorkbookView.CellEndEdit event is solely used for "edit mode"--when a user manually types some value into a cell--and there is nothing in SpreadsheetGear API to expand edit mode to include other forms of input.
The WorkbookView.RangeChanged event will fire whenever a change is made to a cell, including via a cell validation listbox; however, many other actions trigger this event as well, such as changing a cell's NumberFormat, font formats, etc; or inputting a cell value in some other way such as pasting a value, FillDown, Clear, etc. Still, you may be able to use this event to, within some reasonable assurance, get the information you need.
Below is some sample code that demonstrates how you could detect whether RangeChanged was called from a single cell containing cell validation. Additional conditions are used to ensure to the best of our ability that the event was triggered by the user changing a value via the validation dropdown list. Again, this still isn't 100% foolproof for the reasons listed above.
private void workbookView_RangeChanged(object sender, SpreadsheetGear.Windows.Controls.RangeChangedEventArgs e)
{
// Did this RangeChanged action affect only a single cell?
if(e.Range.CellCount == 1)
{
IRange cell = e.Range;
// Does the cell even have cell validation?
if(cell.HasValidation)
{
IValidation validation = e.Range.Validation;
// Is the validation applied to this cell of the "List" type and
// does the inputted value pass validation checks?
if(validation.Type == ValidationType.List && validation.Value)
{
// Do something here, such as shade the cell...
cell.Interior.Color = SpreadsheetGear.Colors.LightGray;
}
}
}
}
Please see the documentation for the IValidation interface members for more information on each of the properties used above.

Related

Google Sheets: Conditionally Shade an Individual Set of Repeating Groups of Cells Based on Value

I have a Google Sheet I use to document my quotes for customers. I've copied and pasted it down the sheet several times. Within each quote is a list validated field where the options are "Won" or "Lost." When I select "Won," I want to turn that background color of JUST that quote green. However, I also only want to shade green the fields that I am not entering text into or accomplishing the calculations on (the data fields); I want to shade the background of the "form" and the "labels." (See screenshot where I did this by hand.)
I've attempted do this myself, but I'm having two issues.
I have to create separate conditional format rules for each quote/group of cells. This is tedious. I'd like, if possible, to create one rule that is able to adapt the conditional test of ="Won" to each group/quote separately.
I have to individually select each and every cell to be highlighted because if I just do A1:G33, all of the cells change color, even the ones in black and gray. I know this is expected, but is there a way around it?
I'm confused why applying the rule to the first group and copying and pasting it doesn't work. All of the quotes change green if the first quote shows "Won." This functionality works correctly with the built-in conditions that test the value of the cell itself. However, custom formulas to test the value of another cell don't "repeat" and operate individually it seems.
EDIT: Link to spreadsheet: https://docs.google.com/spreadsheets/d/1OH16NXLiRzY3-EdZaxmUl5Vp6cQNPzY-_-LV7VIDl8U/edit#gid=983650786
in your case perhaps best would be to color the first table exactly as you wish and then select it, copy it, select the first cell of the next table and:
Use Apps Script
This way you can have a lot of flexibility and its easier to manage.
You seem to already have an onEdit trigger, so you could integrate some more logic into that to test for statues. I can't implement everything you want but this should get you well on the way.
function onEdit(e){
// Getting the information on the edited cell
let editedCell = e.range;
let sheet = editedCell.getSheet()
// If the edited cell is in column 6, in "Quotes" and is value "Won"
if (editedCell.getColumn() == 6 && sheet.getName() == "Quotes" && editedCell.getValue() == "Won") {
// Get the row to know where to change the format
let statusRow = editedCell.getRow();
// Get the range of the whole form
let formRange = sheet.getRange(statusRow, 3, 17, 6)
// Set the background color
formRange.setBackground("green")
}
}
Hopefully you can see how you might extend this to include other ranges. You would need to base everything of the position of the edited cell. I have identified it by its column, the sheet that contains it, and its value. You can extend this to include checks on the value next to it for example. Then to change the color of each black box, you would need to define a range for each, relative to the edited cell.
References
setBackgroundColor
getRange

Xcode swift : connection from buttons to Text Fields

I am new to swift programming and Xcode
However I am creating a dart counter app but having trouble connecting the buttons to Text fields
I have buttons numbered 0-20 on the main story board and three text fields (one for each dart) how do I connect the buttons to the UITextFields - I can’t figure this out
Thanks
Based on my understanding of your issue, you actually need to connect the buttons to the text field in code. There is not going to be a simple way to do this in the interface builder. What you are looking for is to have some action happen when the user presses a number, and this may be added to the current value in the text field.
Create a function that handles any number button being pressed.
#IBAction func buttonPress(sender: UIButton) {
print(sender.tag)
//TODO: process the button based on its tag
}
Update all of the buttons in interface builder to have a tag value according to their number. This will let you handle them all in the same function (above) and differentiate between them.
Update the TODO block to handle the action appropriately. I would start by adding a variable to keep track of which dart number you are on, and using a switch statement to handle putting the value in the appropriate dart text box.
So there is always a current text field. Maintain an instance property that points to it. When the user taps a number, use that instance property to enter that value in that text field. When the user taps Enter, change the instance property to point to the next text field.

Handle accessibility when user click on empty area

General scenario: When user clicks on empty area, control does not goto any other place.
My scenario: When user clicks on empty area, control goes to last cell.
Is there any way to handle the empty area click?
I have already manages accessibilityElements array which comprises of needed UI elements only.
I have kept the isAccessibilityElement false to elements which are not needed
This is occuring on one screen only. I researched about it but no solution found yet.
You can override the accessibilityActivate() of empty area.
Return true if you wish to modify the default implementation i.e., write your custom code for what needs to be done and then return true.
If you don't want to change the default implementation i e., let the OS decide what happens on double tap of empty area, return false. By default, return type is false.
Read more here
https://developer.apple.com/documentation/objectivec/nsobject/1615165-accessibilityactivate

How to set the Focus on Particular Cell in UI Grid

I have a situation where, if I edit Cell1, UI Grid will run validators for Cell1, but I also want to run the validators for Cell2.
If Cell2 value is not proper then I want to set focus on Cell2 with validation message set in uiGridValidateService.setValidator().
I am able to run the validator for Cell2 on Cell1 edit using below statement, but not able to highlight Cell2.
Code:
gridApi.grid.validate.runValidators(rowEntity, colDef, rowEntity['Cell2'], NaN, $scope.gridApi.grid);
How can I put focus on a particular cell in UI Grid?
I solved it by below, hope it will help someone with same requirement,
Rather than trying to set the focus on error field, I just added below code on afterCellEdit().
if (!rowEntity['$$errors' + fieldName]) {
rowEntity['$$errors' + fieldName] = {};
}
rowEntity['$$errors' + fieldName][validatorName] = true;
rowEntity['$$invalid' + fieldName] = true;
Where my fieldName is target field which I want to get validated on every cellEdit. So in my case, even if I am editing value of Cell1, I will pass fieldName='Cell2' and it will get validated against my validator that I will pass as 'validatorName'. If it is not proper value then it will highlight cell2 as red and will show its tooltip.
Hope it will help someone. Let me know if any questions.

How would you go about disabling a button as long as 2 text fields are empty in Objective C?

I have a view controller that controls 2 text fields and an array that displays in a table. How would I go about keeping a button disabled until the 2 fields have at least one character and the array is not empty. I am thinking about using cocoa bindings, however I can't seem to figure out a solution.
Currently my button is binded to
BOOL buttonIsEnabled;
I use that in a notification function in order to keep the button disabled, except the button will only reenable if I call that notification function.
-(void)controlTextDidChange
This means if i make a change in an array, the button wont reenable until I re-enter text. I can't seem to figure out an alternative solution. Any suggestions? Thank you.
One solution:
bind the two text fields two two strings (say text1 and text2)
in the text field bindings check Continuously Updates Value
Add this code:
- (BOOL)buttonIsEnabled {
return (self.text1.length>0 && self.text2.length>0);
}
+ (NSSet *)keyPathsForValuesAffectingButtonIsEnabled {
return [NSSet setWithObjects:#"text1",#"text2",nil];
}
Lastly bind the buttons enabled binding to buttonIsEnabled.
Because of the Continuously Updates Value text1 or text2 will change whenever characters are added to or removed from the text fields.
And the + (NSSet *)keyPathsForValuesAffectingButtonIsEnabled method will cause a Key-Value change notification to be posted for buttonIsEnabled whenever text1 or text2 change.
You can create a custom cell, give outlets to your 2 textfields and button.
Now on cell for row at index path after filling the textfields text values, put a condition checking the length of the textfields. If length is greater than 0 you can enable the button or keep it disable.
Along with this you need to put same code in delegate method (textFieldDidChange) of textfield. So that when ever new text is entered the button gets enable or disabled.

Resources