UltraWinGrid - Get Current Cell/Column for a group by row - infragistics

I am trying to provide quick summary for the selected rows if the active cell is of type double or int. This works fine if the grid is not grouped by any column. But when grid is grouped by one or more columns, there is no active cell when top level rows are selected.
void ultraGrid_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
{
var ultraGrid = ((UltraGrid)sender);
var selected = ultraGrid.Selected;
var hasCells = selected.Cells != null && selected.Cells.Count > 0;
var hasRows = selected.Rows != null && selected.Rows.Count > 0;
if ( !hasCells && !hasRows )
{
statusLabel.Text = string.Empty;
return;
}
UltraGridColumn activeColumn;
var activeCell = ultraGrid.ActiveCell;
if( activeCell == null )
{
var aUIElement = ultraGrid.DisplayLayout.UIElement.ElementFromPoint( ultraGrid.PointToClient(MousePosition));
activeColumn = (UltraGridColumn)aUIElement.GetContext(typeof(UltraGridColumn));
}
else activeColumn = activeCell.Column;
if( activeColumn == null || (activeColumn.DataType != typeof (double) && activeColumn.DataType != typeof (int) ) )
{
statusLabel.Text = string.Empty;
return;
}
//code to calculate summaries for selected rows or cells and active column
}
But aUIElement.GetContext(typeof(UltraGridColumn)) always return null when group by rows are selected.
How do I get active column / cell when group by rows are selected?

If the column from the GetContext is null, make another GetContext call for the type UltraGridGroupByRow. If an instance is returned, get the Column property from it and that will give you the grouped column to which that row refers.

Related

Googlescript 'if' question - do only one of two tasks

I have 'else if' statements and I need it to be called only if the previous 'if' does not execute. First 'if' (check status) work perfect, second work to, but the 'else if' is done every time because there are different types in the table (A, B, C e.t.c)
Edit:
1. New line must be add if there's no open A;
2. If there are open more than one A - all are must be closed;
3. Ignore all other types and add new line only if there are no As open;
Here is my code:
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SheetName');
var data = sheet.getRange(2,1,sheet.getLastRow(),2).getValues();
var nextRow = SpreadsheetApp.getActiveSheet().getDataRange().getLastRow()+1;
for (var i=0; i<data.length; i++){
var row = data[i];
var type = row[0];
var status = row[1];
//check it always
if (status != 'close'){
//check first and if it's true don't do 'else if'
if (type == 'A') {
sheet.getRange(i+2,2).setValue('close')
}
//this should only be called if the previous 'if' is not true
else if (type != 'A' && type != ''){
var values = [['A','open']];
sheet.getRange("A"+nextRow+":B"+nextRow).setValues(values);
}
}
}
}
Flow:
Loop through all data to find if there's a "A:Open"
If found in all of data, just close that row
else, Add a new line: "A:Open"
Use a Boolean variable(isThereASingleAOpen) to keep track of A:Open found status
Sample script:
function closeAandAddOpenA() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SheetName');
//Separate range and data
var range = sheet.getRange(2, 1, sheet.getLastRow(), 2);
var data = range.getValues();
//Is there a A Open in the data? Let's assume there's none
var isThereASingleAOpen = false;
//Loop through data array
for (var i = 0; i < data.length; i++) {
var row = data[i];
var type = row[0];
var status = row[1];
//If status is != close and type == 'A'
if (status != 'close' && type == 'A') {
//Change current row status to close in the data array
row[1] = 'close';
//Oops We were wrong. There was a A open in the data
isThereASingleAOpen = true;
}
} //Loop closed
//Set the modified data back to the range
//Batch operations are faster
range.setValues(data);
//if there is NOT a single A open in all of data, Append a new line
if (!isThereASingleAOpen) {
sheet.appendRow(['A', 'Open']);
}
}

Adding items to a Google Forms list from a spreadsheet range

I am struggling to get past the last line in this code any help will be appreciated:
The error I am getting is "Array is empty: values (line 16, file "Code")". I have double checked the item ID, the spreadsheet ID and that there is data for it to pick up within the correct range. Any pointers or insights...?
function GetFleet() {
var ssDEFECTS = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var rngFLEET = ssDEFECTS.getDataRange();
var values = rngFLEET.getValues();
var FleetList = [];
//Use column 0 and ignore row 1 (headers)
for (var i = 1; i <= values.length; i++) {
var v = values[i] && values[i][0];
v && values.push(v)
}
// Form ID & List ID
var DefectsForm = FormApp.openById('<FORM KEY ID>');
DefectsForm.getItemById(794194842).asListItem().setChoiceValues(FleetList);
};
Nothing is pushed to your array FleetList. Also the coding in your loop is faulty.
Assuming you want to push the first column (not including the header),
try this and see if it works
function GetFleet() {
var values = SpreadsheetApp.getActiveSpreadsheet()
.getSheets()[0].getDataRange()
.getValues();
var FleetList = [];
//Use column 0 and ignore row 1 (headers)
for (var i = 1, len = values.length; i < len; i++) {
FleetList.push(values[i][0])
}
// Form ID & List ID
var DefectsForm = FormApp.openById('<FORM KEY ID>');
DefectsForm.getItemById(794194842)
.asListItem()
.setChoiceValues(FleetList);
};

Number of entries in 'li' - list form (on Datatable)

I am totally new here, I will try to explain. On each data table header we have show entries, were we have options something like 10,20,30... This is normally displayed in select options, Insted i want it to be in List in ul li.
You need to modify jquery.dataTables.js file, refer below code which create menu item for length:- (Please note, this is code from jquery.dataTables.js file and you need to modify according to convert select option dropdown to ul li list)
/* This can be overruled by not using the _MENU_ var/macro in the language variable */
var sName = 'name="'+oSettings.sTableId+'_length"';
var sStdMenu = '<select size="1" '+sName+'>';
var i, iLen;
var aLengthMenu = oSettings.aLengthMenu;
if ( aLengthMenu.length == 2 && typeof aLengthMenu[0] === 'object' &&
typeof aLengthMenu[1] === 'object' )
{
for ( i=0, iLen=aLengthMenu[0].length ; i<iLen ; i++ )
{
sStdMenu += '<option value="'+aLengthMenu[0][i]+'">'+aLengthMenu[1][i]+'</option>';
}
}
else
{
for ( i=0, iLen=aLengthMenu.length ; i<iLen ; i++ )
{
sStdMenu += '<option value="'+aLengthMenu[i]+'">'+aLengthMenu[i]+'</option>';
}
}
sStdMenu += '</select>';
var nLength = document.createElement( 'div' );
if ( !oSettings.aanFeatures.l )
{
nLength.id = oSettings.sTableId+'_length';
}
nLength.className = oSettings.oClasses.sLength;
nLength.innerHTML = '<label>'+oSettings.oLanguage.sLengthMenu.replace( '_MENU_', sStdMenu )+'</label>';
/*
* Set the length to the current display length - thanks to Andrea Pavlovic for this fix,
* and Stefan Skopnik for fixing the fix!
*/
$('select option[value="'+oSettings._iDisplayLength+'"]', nLength).attr("selected", true);
$('select', nLength).bind( 'change.DT', function(e) {
var iVal = $(this).val();
/* Update all other length options for the new display */
var n = oSettings.aanFeatures.l;
for ( i=0, iLen=n.length ; i<iLen ; i++ )
{
if ( n[i] != this.parentNode )
{
$('select', n[i]).val( iVal );
}
}
/* Redraw the table */
oSettings._iDisplayLength = parseInt(iVal, 10);
_fnCalculateEnd( oSettings );
/* If we have space to show extra rows (backing up from the end point - then do so */
if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
{
oSettings._iDisplayStart = oSettings.fnDisplayEnd() - oSettings._iDisplayLength;
if ( oSettings._iDisplayStart < 0 )
{
oSettings._iDisplayStart = 0;
}
}
if ( oSettings._iDisplayLength == -1 )
{
oSettings._iDisplayStart = 0;
}
_fnDraw( oSettings );
} );

Open XML Excel Cell Formatting

I am trying to export to excel using Open XML with simple formatting. Export to Excel is working. The problem is with formatting the data. I am trying to have very basic formatting. i.e. the Column names should be in bold and rest of the content in normal font. This is what I did. Please let me know where am I going wrong.
private Stylesheet GenerateStyleSheet()
{
return new Stylesheet(
new Fonts(
new Font(new DocumentFormat.OpenXml.Spreadsheet.FontSize { Val = 12},
new Bold(),
new Font(new DocumentFormat.OpenXml.Spreadsheet.FontSize { Val = 12}))
)
);
}
protected void ExportExcel(DataTable dtExport)
{
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
//"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" '"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" '"application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=Test.xlsx");
Response.Charset = "";
this.EnableViewState = false;
MemoryStream ms = new MemoryStream();
SpreadsheetDocument objSpreadsheet = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook);
WorkbookPart objWorkbookPart = objSpreadsheet.AddWorkbookPart();
objWorkbookPart.Workbook = new Workbook();
WorksheetPart objSheetPart = objWorkbookPart.AddNewPart<WorksheetPart>();
objSheetPart.Worksheet = new Worksheet(new SheetData());
Sheets objSheets = objSpreadsheet.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
Sheet objSheet = new Sheet();
objSheet.Id = objSpreadsheet.WorkbookPart.GetIdOfPart(objSheetPart);
objSheet.SheetId = 1;
objSheet.Name = "mySheet";
objSheets.Append(objSheet);
WorkbookStylesPart stylesPart = objSpreadsheet.WorkbookPart.AddNewPart<WorkbookStylesPart>();
stylesPart.Stylesheet = GenerateStyleSheet();
stylesPart.Stylesheet.Save();
objSheetPart.Worksheet.Save();
objSpreadsheet.WorkbookPart.Workbook.Save();
for (int cols = 0; cols < dtExport.Columns.Count; cols++)
{
Cell objCell = InsertCellInWorksheet(GetColumnName(cols), 1, objSheetPart);
objCell.CellValue = new CellValue(dtExport.Columns[cols].ColumnName);
objCell.DataType = new EnumValue<CellValues>(CellValues.String);
objCell.StyleIndex = 0;
}
objSheetPart.Worksheet.Save();
objSpreadsheet.WorkbookPart.Workbook.Save();
for (uint row = 0; row < dtExport.Rows.Count; row++)
{
for (int cols = 0; cols < dtExport.Columns.Count; cols++)
{
//row + 2 as we need to start adding data from second row. First row is left for header
Cell objCell = InsertCellInWorksheet(GetColumnName(cols), row + 2, objSheetPart);
objCell.CellValue = new CellValue(Convert.ToString(dtExport.Rows[Convert.ToInt32(row)][cols]));
objCell.DataType = new EnumValue<CellValues>(CellValues.String);
objCell.StyleIndex = 1;
}
}
objSheetPart.Worksheet.Save();
objSpreadsheet.WorkbookPart.Workbook.Save();
objSpreadsheet.Close();
ms.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
// Given a column name, a row index, and a WorksheetPart, inserts a cell into the worksheet.
// If the cell already exists, return it.
private Cell InsertCellInWorksheet(string columnName, uint rowIndex, WorksheetPart worksheetPart)
{
Worksheet worksheet = worksheetPart.Worksheet;
SheetData sheetData = worksheet.GetFirstChild<SheetData>();
string cellReference = (columnName + rowIndex.ToString());
// If the worksheet does not contain a row with the specified row index, insert one.
Row row = default(Row);
if ((sheetData.Elements<Row>().Where(r => r.RowIndex.Value == rowIndex).Count() != 0))
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex.Value == rowIndex).First();
}
else
{
row = new Row();
row.RowIndex = rowIndex;
sheetData.Append(row);
}
// If there is not a cell with the specified column name, insert one.
if ((row.Elements<Cell>().Where(c => c.CellReference.Value == columnName + rowIndex.ToString()).Count() > 0))
{
return row.Elements<Cell>().Where(c => c.CellReference.Value == cellReference).First();
}
else
{
// Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
Cell refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
if ((string.Compare(cell.CellReference.Value, cellReference, true) > 0))
{
refCell = cell;
break; // TODO: might not be correct. Was : Exit For
}
}
Cell newCell = new Cell();
newCell.CellReference = cellReference;
row.InsertBefore(newCell, refCell);
return newCell;
}
}
It seems like you are missing a ")" after your first font creation. So then you end opp with only one font index (the default one)
Below is the code I use for exactly what you are asking for.
You might remove fills and borders and remove them from cellformat, but I had some syntax problems while writing this so I just left it when it all worked :-)
private Stylesheet GenerateStyleSheet()
{
return new Stylesheet(
new Fonts(
// Index 0 - Default font.
new Font(
new FontSize() { Val = 11 },
new Color() { Rgb = new HexBinaryValue() { Value = "000000" } }
),
new Font(
new Bold(),
new FontSize() { Val = 11 },
new Color() { Rgb = new HexBinaryValue() { Value = "000000" } }
)
),
new Fills(
// Index 0 - Default fill.
new Fill(
new PatternFill() { PatternType = PatternValues.None })
),
new Borders(
// Index 0 - Default border.
new Border(
new LeftBorder(),
new RightBorder(),
new TopBorder(),
new BottomBorder(),
new DiagonalBorder())
),
new CellFormats(
// Index 0 - Default cell style
new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 },
new CellFormat() { FontId = 1, FillId = 0, BorderId = 0, ApplyFont = true }
)
);
}

Flex 3 - how to select an item in the list as default?

how to select an item in the list as default
default selected item say of index 0
I tried stuff like this --
listid.selectedIndex = somevalueinmyprogram - 1; // 0
but when i debug this i get
_selectedIndex = 0
selectedIndex = -1
and default value is not selected why so?
[i have already checked for the obvious that somevaluefrommyprogram is not equal to 0]
Help!
I have found that if you set the selectedItems by defining an array of selected items it works better than the selectedIndex.
function setSelectedCategories():void{
var selectedItems :Array = new Array();
for each (var selectedCategory:Category in entry.categories) {
for each (var category:Category in categories) {
if (selectedCategory.categoryID == category.categoryID){
selectedItems .push(category);
break;
}
}
}
categoriesList.selectedItems = selectedItems ;
}
OR using the selectedIndices works if you want to use an array that contains the indexes that you want to be selected.
for ( var i:int=0; i < userIpods.length; i++ ) {
//j will represent the list item's index value
for ( var j:int = 0; j < iPodAry.length; j++) {
if ( userIpods[i] == iPodAry[j].id ) {
selectedIpodIndices.push( j );
break;
} //end if
} //end for ( var iPodObj:Object in iPodAry) {
} //end for ( var i:int in userIpods )
/*mark as selected those index values in the
selectedIpodIndices array*/
iPodList.selectedIndices = selectedIpodIndices ;