Programmatically scrolling WPF 4 DataGrid to end - wpfdatagrid

Does anyone know of a reliable approach for scrolling a WPF DataGrid (.NET 4) to the last row programmatically?
I'm aware of ScrollIntoView(Items[Items.Count-1]), but this works only if the items are unique.
For instance, consider the following DataGrid which displays all the installed cultures, followed by all the installed cultures:
var cultures = System.Globalization.CultureInfo.GetCultures (System.Globalization.CultureTypes.AllCultures);
var timesTwo = cultures.Concat (cultures).ToArray();
var grid = new DataGrid { ItemsSource = timesTwo };
How can this grid be programmatically scrolled to the last row?
P.S. Another problem with using ScrollIntoView is that if the grid is itself in a scrollable container (e.g., inside another grid), then ScrollIntoView scrolls not only its own grid, but the outer grid as well such that requested element is visible on the screen. This might be beneficial in some cases, but certainly not in others.

For anyone with this problem, the following seems to do the trick:
var scrollerViewer = GetScrollViewer();
if (scrollerViewer != null) scrollerViewer.ScrollToEnd();
...
ScrollViewer GetScrollViewer()
{
if (VisualTreeHelper.GetChildrenCount (this) == 0) return null;
var x = VisualTreeHelper.GetChild (this, 0);
if (x == null) return null;
if (VisualTreeHelper.GetChildrenCount (x) == 0) return null;
return VisualTreeHelper.GetChild (x, 0) as ScrollViewer;
}

Related

Restricted Selection dGrid data

I have a grid created with dGrid with the "Pagination" extension end I needto click on the check-all checkbox on the header of dgrid and selecting only the rows in the current page leaving the rows of the other pages not checked!!!
Is it possible this???
Not out of the box. But I had the same requirement in a different situation and added a new method to my grid.
This code will check all visible for user checkboxes in the grid. I think it should work in your situation also. Add this to your grid and call grid.checkAll()
checkAll:function(){
this._selected = [];
this.clearSelection();
array.forEach(query("input[type=checkbox]",this.contentNode), function(input, i){
var isVisible = input.offsetWidth > 0 || input.offsetHeight > 0; //check if row checkbox is visible for user
if(isVisible){
var row = this.row(input.parentNode);
if (this._selected.indexOf(row) == -1){
this._selected.push(row);
}
input.checked = true;
input.setAttribute("aria-checked", true);
}
},this);
},

Using extendscript (javascript) how can I get the color values from the Photoshop color table

I'm writing a Photoshop script in extendscript/javascript and I'm trying to verify that the document is using just one color (plus transparency). What I would like to do is change the document mode to Indexed Color and then get the values in the color table.
I have successfully changed the document mode to Indexed Color but can't figure out how to access the color table or the color values inside of it.
My working alternative is to use a colorSampler to compare the values of each pixel, but that can take a couple of minutes to run on larger documents and speed is an issue for this project.
Please let me know if there is a way to access the color table or if you see a way to reduce the time it takes to run this function.
function sample_color(doc, sample_rate) {
var status = 'PASS'
var color_sampler = doc.colorSamplers.add([0,0])
var color_val = false //first (and hopefully only) color value in the document
var broke = false
for (x=1; x < doc.width; x+=sample_rate){
if (broke){
break
}
for (y=1; y < doc.height; y+=sample_rate){
color_sampler.move([UnitValue(x, 'px'), UnitValue(y, 'px')])
try{
var color = color_sampler.color //color of the current pixel
} catch(e) {
var color = false //color_sampler.color fails if the pixel is transparent
}
if (color != false){
if (color_val != false){
if (!color.isEqual(color_val)){
status = 'FAIL'
broke = true
break
}
} else {
color_val = color
}
}
}
}
color_sampler.remove()
return status
}
xbytor has written a couple of scripts for accessing colour tables. This link may be of use to you.

updateSeries during onclick event of a chart column works as expected only when debugging in Chrome

Using dojo, I create a chart with ColumnsPlot.
The chart is created and displayed the way I want it.
In order to handle a click on a column and to change the color of the clicked column I have the code below:
var handler = barChart.connectToPlot("default", function (event) {
if (event.type == "onclick") {
var currentSeriesData = event.run.data;
barChart.updateSeries("Yearly Offense Count", reverseColors(currentSeriesData, event.index));
barChart.render();
}
});
And the reverseColors is:
reverseColors = function (data, index) {
var tempData = [];
for (var i = 0; i < data.length; i++) {
tempData.push(data[i]);
if (i == index) {
tempData[i].fill = "red";
} else {
tempData[i].fill = "green";
}
}
console.log(i + " - " + tempData[i].fill);
return tempData;
}
I am testing in Google and using the Developers Tools to debug. If I set a break point inside the if statement and debug the app, the barChart is updated and the clicked columns get a red color, and all the others are green (as desired).
If I am not debugging, the barChart is updated, but all columns are green (originally chart is created with all green columns except one red column).
The reverseColors function returns the data in the correct format and wiht the correct fill while debugging, and when not debugging in the console I have 1 red and the rest of the items are green, as expected. But my chart has only green columns.
What am I messing up?
Dojo beginner!
Edit: Doesn't work in Chrome, works once in a blue moon in Firefox, and works fine is IE8.
The chart had a Highlight defined.
Removing the Highlight solved the problem.

DataGrid returning null selectedItem

I have a dojo (1.8.1) DataGrid where I cannot retrieve all the selected items in the DataGrid (roughly 171 records in the grid). The problem is that some of data returned to selectedItem are null.
Interesting, If i scroll all the way to the bottom of the DataGrid and then run though the code below, I get all the records..This is weird..
var gridy = dijit.byId("grid");
var items = gridy.selection.getSelected();
if (items.length) {
dojo.forEach(items, function(selectedItem) {
if (selectedItem !== null) {
dojo.forEach(gridy.store.getAttributes(selectedItem),
function(attribute){
var value = gridy.store.getValues(selectedItem, attribute);
alert('attribute: ' + attribute + ', value: ' + value);
});
}
});
}
So, when all items in the grid are selected (171) I only get 50 items showing as selected and the rest are null for selectedItem variable. Strange problem, seem like a bug in DataGrid??
Thx!!
It could be due to paging (see DataGrid-tutorial at "Paging and Virtual Scrolling"). "only a small subset of the data is ever rendered at one time". Therefore, a nasty workaround could be to set the rowsPerPage-property of your DataGrid to a high value (like 1000) when instanciating it.. It should be higher then the expected maximum amount of rows to be displayd in the grid at all ever.

Eclipse RCP: Is it possible to shift the fields up without redrawing?

In my editor, I have a composite containing a label control right at the top which flashes informative message in red colour whenever the user enters erroneous inputs in any of the below lying fields. The text keeps changing dynamically depending on user's input. I am able to achieve the effect of displaying red coloured text on erroneous inputs and displaying nothing in the label for correct inputs.
But, I want that when there is no error to display in the label composite, the rest of the below fields shift up in display. And when there is error to display, the error should appear in it's place(at the top of all other fields) pushing the other fields down.
Is there a way to achieve this effect without redrawing all the controls again?
Yes, call layout (true) on the parent.
For example I have a view that has a search bar at the top who's visibility can be toggled. I have a method to create the search composite and one to remove it:
private void createNameSearchBar () {
mySearchControl = new CardSearchControl (myViewComposite, SWT.NONE);
mySearchControl.setSearchListener (this);
}
private void disposeNameSearchBar () {
mySearchControl.dispose ();
mySearchControl = null;
}
private CardSearchControl mySearchControl = null;
private Composite myViewComposite;
private boolean mySearchBarState;
To hide or show the search bar control I call this method (myViewComposite is the top level control that owns the search bar and all the other contorls):
public void setSearchBarState (boolean show) {
mySearchBarState = show;
if (myViewComposite == null || myViewComposite.isDisposed ())
return; // no work to do
if (mySearchBarState && mySearchControl == null) {
createNameSearchBar ();
mySearchControl.moveAbove (null);
myViewComposite.layout (true);
} else if (!mySearchBarState && mySearchControl != null) {
disposeNameSearchBar ();
myViewComposite.layout (true);
}
}