Silverlight alternative to AlternatingRowsDefaultCellStyle - silverlight-4.0

I am trying to set the cell templates of the alternate rows of a DataGrid, similar to the "AlternatingRowBackground", but not just for background colour.
Is there an alternative to the "AlternatingRowsDefaultCellStyle" of the DataGridView?
I can do this programmatically in my own class inheriting of of the DataGrid (using the LoadingRow event). The problem with this is I need to know the index of the row to determine what style to use. I can't seem to find a way of getting the index of a row.

Found out there is a GetIndex method on the LoadingRow event, so I can use that to determine which style to assign the row.
this.LoadingRow += (s,e) =>
{
if(e.Row.GetIndex() % 2 == 1)
e.Row.Style = //alternate Style
};

Related

Acrobat XI Forms - Radio Button Action on click

In a fillable form, I would like the two adjacent fields to become shaded (no input available) if the N/A radio button is selected. If either the Yes or No radio button is selected, I would like the first adjacent field to take the value from the PointValue field. How would I accomplish this? Thank you for your help.
That can be accomplished in various ways. One possibility would be the following, which you add to the form logic calculation script (if this is the only one, then be it), which you attach to a hidden (text) field whose sole purpose is to provide a holder for the form's calculation logic. BTW, this approach is considered best practice for a smart form, because it gives maximum control over the calculations, and creates the most efficient form.
Anyway, let's assume the group of checkboxes or radiobuttons is named "mySelect", and the field with the result/to be greyed out is named myResult. The return value of the n/a button shall be "na"
Then, you would have the following piece of code in the calculation script mentioned above:
if (this.getField("mySelect").value != "na") {
this.getField("myResult").readonly = false ;
this.getField("myResult").strokeColor = color.gray ;
this.getField("myResult").value = this.getField("mySelect").value.toString().replace(/Off/gim, "") ;
} else {
this.getField("myResult").readonly = true ;
this.getField("myResult").strokeColor = color.blac, ;
this.getField("myResult").value = "" ;
}
And that should do it.

Programmatically set dgrid row as active

I'm trying to programmatically set a dgrid row as active, not just selected. I have a dojo dgrid OnDemandList which is using the Selection and Keyboard Mixins.
Using the select(row) method I can programmatically select a given row, but that row is not active. When a row is active, I can use the Up and Down arrow keys to navigate to the rows above and below it. When a row is just selected, the row is highlighted but the arrows keys do not work.
Clicking the row with the mouse will make it active and selected, but I'm trying to build my interface to be 100% usable with just the keyboard.
Ok, took me awhile but got it figured out. What I was really trying to do was add focus to a row. The code for doing that was in dgrid/Keyboard.js under the _focusOnNode method.
The actual code to change focus from row currentFocusedNode to row focusedNode is:
if(currentFocusedNode){
// Clean up previously-focused element
// Remove the class name and the tabIndex attribute
put(currentFocusedNode, "!dgrid-focus[!tabIndex]");
if(has("ie") < 8){
// Clean up after workaround below (for non-input cases)
currentFocusedNode.style.position = "";
}
}
if(has("ie") < 8){
// setting the position to relative magically makes the outline
// work properly for focusing later on with old IE.
// (can't be done a priori with CSS or screws up the entire table)
focusedNode.style.position = "relative";
}
focusedNode.tabIndex = grid.tabIndex;
focusedNode.focus();
put(focusedNode, ".dgrid-focus");
The code above is really just a code fragment, for it to work you will have to declare "dojo/has" and "put-selector/put" first as well as define the currentFocusedNode and focusedNode. But I'm leaving that as an exercise for the reader ;-)
Also note that this only changes the "focus", it will not select the focusedNode but that can easily be done using grid.select(focusedNode);

How to show button cell (check box) title in table view, using bindings

I am trying a simple application where I have a mutable array of mutable dictionaries, such as -
NSMutableDictionary *sample6 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"title6",#"title",[NSNumber numberWithBool:NO],#"state", nil];
In IB I created a table view with NSButtonCell (check box).
I was able to show checkboxes state (checked or unchecked), using following table column bindings:
Value - ArrayController.arrangedObjects.state
In this case it shows an array of checkboxes with title - "Check" as shown in below screen-shot:
Now my aim is to show checkboxes title using bindings, such that it
gets value from same mutable dictionary from which it is getting its
state.
I tried following binding for button cell but it did not work:
title -> ArrayController.selection.title
I also tried this binding for button cell :
title -> ArrayController.arrangedObjects.title
but it didn't work, it appeared like this after using above binding:
Can any one suggest me which controller key to use and if this is not the correct way to show titles then what is the correct way to do so?
Unfortunately you'll need to write a little code if you want to do it this way. When binding table column values to an array, the table column is handling taking the prototype data cell, setting its values, and "stamping" it in place for each row. The button cell's bindings aren't exposed "through" the table column, so a simple binding won't do it for you.
To Answer Your Question
So. Since only the value binding is exposed, the title must be set manually if you really want the checkbox's title to reflect the value (ie, you really want the checkbox to handle both the check state and displaying the title). To do this, you have to mix bindings with < NSTableDelegateProtocol > . Use the -tableView:willDisplayCell:forTableColumn:row: method to set the cell's -title property to that of the proper object in your array controller's -arrangedObjects array each time you're asked. Mixing bindings and data source / delegate methods is actually quite common for more than the most basic applications, so don't worry that you're doing something dirty. Note: you won't be able to support editing the title by doing this since it's a checkbox.
An Alternative Design
Personally, I'd avoid all that and just add a separate table column for the title. Bind the new column's value to the array controller's arrangedObjects.title and turn off the checkbox button cell's title so only the checkbox itself is displayed. That simplifies the whole thing greatly and allows editing the title.

Silverlight 4 Datagrid, Set RowBackground

I know that the data grid isn't designed to directly access each row. My problem is I need to highlight rows based on certain conditions but not just at loading time. After the grid has been loaded there can be changes that occur on a collection that is not the collection that the grid is populated from so changes to this collection obviously won't affect the grid.
Sample Data Diagram:
[GridCollection] [SecondaryCollection]
{ID = 0, Name = "Test A"} {ID = 0, GridCollectionID = 0, Name = "Test A Linked"}
{ID = 1, Name = "Test B"}
So in this case GridCollection item 0 would be highlighted in the grid. But if I add another item to the SecondaryCollection this item would be should highlighted in the grid.
Now I can force an update to the grid's ItemsSource but this seems hacky. Anyone got any ideas on how to approach this issue?
This would be really easy to achieve by using Prism's EventAggregator:
Make sure the items in GridCollection implement INotifyPropertyChanged
Add a boolean IsHighlight property to the class of items in GridCollection
When an item is added to SecondaryCollection, fire an event using the event aggregator, using the GridCollectionID as payload.
Subscribe to this event on GridCollection and set IsHighlight to true.
On the DataGrid, set your conditional format to be on when IsHighlight is true.
This methodology is decoupled and robust and it let's you make the highlight look as you want and change any time, even using animations.

Beginner question - VB - change a button based on an integer

I have a form with a large number of buttons on it, each named btn1 through btn25. I have another button that is generating a random number and saving it to an integer variable intDrawn.
I'd like to know if there's a simple way to alter a particular button based on the result in intDrawn; if intDrawn = 5, then I want to change the font in btn5, for example.
Is there a way to alter a control programmatically like this? I'm using Visual Basic Express 2008.
It sounds like you'd be better to use a control array. Give your buttons the same name and then use the integer result to change the font for that particular control number in the array.
http://msdn.microsoft.com/en-us/library/kxt4418a%28VS.80%29.aspx - VB6
http://msdn.microsoft.com/en-us/library/aa289500%28VS.71%29.aspx - VB.Net
Create a control array of buttons, and then use the index into this array to alter a particular button.
Control Arrays
There is also a "stupid" way to do this. Add an invisible textbox and after getting your random number you can just text1.text = "btn" + randomnumber, and then change the color or whatever you wish using text1.text.
Control Array is the better choice, but you could also achieve it with reflection.