protected List <ExpandedRowList> expandedRowList; //keeps track of all nodes shown in table #region Overridden events protected override void OnCellValueNeeded(DataGridViewCellValueEventArgs e) { if (CellValueNeeded == null) { throw new InvalidOperationException("TreeDataGridView requires at least one handler for CellValueNeeded"); } // DataGridView may ask for cells after RowCount is set to 0 in order to commit changes if (expandedRowList == null || e.RowIndex >= expandedRowList.Count) { return; } //converts row number into hierarchy list, understandable by user-specified value-retrieval function var rowInfo = expandedRowList[e.RowIndex]; var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(e.ColumnIndex, rowInfo.RowIndexHierarchy); CellValueNeeded(this, cellValueEventArgs); e.Value = cellValueEventArgs.Value; if (e.ColumnIndex == 0) { rowInfo.ChildRowCount = cellValueEventArgs.ChildRowCount; rowInfo.HasChildRows = cellValueEventArgs.HasChildRows; } }
/// <summary> /// Show child rows /// </summary> /// <param name="index">Which row to expand</param> /// <param name="maxDepth">How far down to expand</param> /// <returns></returns> protected int expand(int index, int maxDepth) { var rowInfo = expandedRowList[index]; if (!rowInfo.HasChildRows || rowInfo.ExpandedChildRows.Count > 0 && maxDepth == 0) { return(0); // row already expanded, nothing to do } int rowsAdded = 0; if (rowInfo.ExpandedChildRows.Count == 0) { if (!rowInfo.ChildRowCount.HasValue) { var e = new TreeDataGridViewChildRowCountNeededEventArgs(rowInfo.RowIndexHierarchy); OnChildRowCountNeeded(e); rowInfo.ChildRowCount = e.ChildRowCount; } var childRowList = new List <ExpandedRowList>(rowInfo.ChildRowCount.Value); for (int j = 0; j < rowInfo.ChildRowCount; ++j) { //get the content of the child row and add it to list to be inserted var childRowInfo = new ExpandedRowList(rowInfo.RowIndexHierarchy, j); var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, childRowInfo.RowIndexHierarchy); CellValueNeeded(this, cellValueEventArgs); childRowInfo.ChildRowCount = cellValueEventArgs.ChildRowCount; childRowInfo.HasChildRows = cellValueEventArgs.HasChildRows; childRowList.Add(childRowInfo); } //insert new rows into table rowInfo.ExpandedChildRows = childRowList; expandedRowList.InsertRange(index + 1, childRowList); rowsAdded = childRowList.Count; } //If more expansion is needed recurse back to the begining if (maxDepth > rowInfo.RowIndexHierarchy.Count) { for (int j = 0; j < rowInfo.ChildRowCount; ++j) { rowsAdded += expand(index + rowsAdded + 1 - rowInfo.ChildRowCount.Value + j, maxDepth); } } return(rowsAdded); }
void dataGridView_CellValueNeeded(object sender, TreeDataGridViewCellValueEventArgs e) { var importSettingsRow = rows[e.RowIndexHierarchy[0]]; if (e.RowIndexHierarchy.Count == 1) { e.ChildRowCount = importSettingsRow.Analysis.parameters.Count; if (e.ColumnIndex == analysisNameColumn.Index) { e.Value = importSettingsRow.Analysis.name; } else if (e.ColumnIndex == databaseColumn.Index) { e.Value = importSettingsRow.ImportSettings.proteinDatabaseFilepath; } else if (e.ColumnIndex == decoyPrefixColumn.Index) { e.Value = importSettingsRow.DecoyPrefix; } else if (e.ColumnIndex == maxFDRColumn.Index) { e.Value = importSettingsRow.ImportSettings.maxQValue; } else if (e.ColumnIndex == maxRankColumn.Index) { e.Value = importSettingsRow.ImportSettings.maxResultRank; } else if (e.ColumnIndex == ignoreUnmappedPeptidesColumn.Index) { e.Value = importSettingsRow.ImportSettings.ignoreUnmappedPeptides; } else if (e.ColumnIndex == qonverterSettingsColumn.Index) { e.Value = importSettingsRow.QonverterSettingsPreset; } } else if (e.ColumnIndex == 0) { e.Value = importSettingsRow.Analysis.parameters.ElementAt(e.RowIndexHierarchy[1]).Key.Replace("Config: ", ""); } else if (e.ColumnIndex == 1) { e.Value = importSettingsRow.Analysis.parameters.ElementAt(e.RowIndexHierarchy[1]).Value; } }
protected override void OnCellValuePushed(DataGridViewCellValueEventArgs e) { if (CellValuePushed == null) { return; } // DataGridView may ask for cells after RowCount is set to 0 in order to commit changes if (expandedRowList == null || e.RowIndex >= expandedRowList.Count) { return; } //converts row number into hierarchy list, understandable by user-specified value-retrieval function var rowInfo = expandedRowList[e.RowIndex]; var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(e.ColumnIndex, rowInfo.RowIndexHierarchy); cellValueEventArgs.Value = e.Value; CellValuePushed(this, cellValueEventArgs); }
void dataGridView_CellValuePushed(object sender, TreeDataGridViewCellValueEventArgs e) { double temp; var importSettingsRow = rows[e.RowIndexHierarchy[0]]; if (e.RowIndexHierarchy.Count == 1) { if (e.ColumnIndex == analysisNameColumn.Index) { importSettingsRow.Analysis.name = (string)e.Value; } else if (e.ColumnIndex == databaseColumn.Index) { importSettingsRow.ImportSettings.proteinDatabaseFilepath = (string)e.Value; } else if (e.ColumnIndex == decoyPrefixColumn.Index) { importSettingsRow.DecoyPrefix = (string)e.Value; } else if (e.ColumnIndex == maxFDRColumn.Index && double.TryParse(e.Value.ToString(), out temp)) { importSettingsRow.ImportSettings.maxQValue = Convert.ToDouble(e.Value); } else if (e.ColumnIndex == maxRankColumn.Index) { importSettingsRow.ImportSettings.maxResultRank = Convert.ToInt32(e.Value); } else if (e.ColumnIndex == ignoreUnmappedPeptidesColumn.Index) { importSettingsRow.ImportSettings.ignoreUnmappedPeptides = (bool)e.Value; } else if (e.ColumnIndex == qonverterSettingsColumn.Index) { importSettingsRow.QonverterSettingsPreset = (string)e.Value; } } }
private void treeDataGridView_CellValueNeeded (object sender, TreeDataGridViewCellValueEventArgs e) { if (e.RowIndexHierarchy.First() >= rows.Count) { e.Value = null; return; } Row baseRow = rows[e.RowIndexHierarchy.First()]; for (int i = 1; i < e.RowIndexHierarchy.Count; ++i) { getChildren(baseRow); // populate ChildRows if necessary baseRow = baseRow.ChildRows[e.RowIndexHierarchy[i]]; } if (baseRow is AnalysisRow) { var row = baseRow as AnalysisRow; e.ChildRowCount = row.Analysis.Parameters.Count; } e.Value = getCellValue(e.ColumnIndex, baseRow); }
void dataGridView_CellValueNeeded(object sender, TreeDataGridViewCellValueEventArgs e) { var importSettingsRow = rows[e.RowIndexHierarchy[0]]; if (e.RowIndexHierarchy.Count == 1) { e.ChildRowCount = importSettingsRow.Analysis.parameters.Count; if (e.ColumnIndex == analysisNameColumn.Index) e.Value = importSettingsRow.Analysis.name; else if (e.ColumnIndex == databaseColumn.Index) e.Value = importSettingsRow.ImportSettings.proteinDatabaseFilepath; else if (e.ColumnIndex == decoyPrefixColumn.Index) e.Value = importSettingsRow.DecoyPrefix; else if (e.ColumnIndex == maxFDRColumn.Index) e.Value = importSettingsRow.ImportSettings.maxQValue; else if (e.ColumnIndex == maxRankColumn.Index) e.Value = importSettingsRow.ImportSettings.maxResultRank; else if (e.ColumnIndex == ignoreUnmappedPeptidesColumn.Index) e.Value = importSettingsRow.ImportSettings.ignoreUnmappedPeptides; else if (e.ColumnIndex == qonverterSettingsColumn.Index) e.Value = importSettingsRow.QonverterSettingsPreset; } else if (e.ColumnIndex == 0) e.Value = importSettingsRow.Analysis.parameters.ElementAt(e.RowIndexHierarchy[1]).Key.Replace("Config: ", ""); else if (e.ColumnIndex == 1) e.Value = importSettingsRow.Analysis.parameters.ElementAt(e.RowIndexHierarchy[1]).Value; }
void dataGridView_CellValuePushed(object sender, TreeDataGridViewCellValueEventArgs e) { double temp; var importSettingsRow = rows[e.RowIndexHierarchy[0]]; if (e.RowIndexHierarchy.Count == 1) { if (e.ColumnIndex == analysisNameColumn.Index) importSettingsRow.Analysis.name = (string) e.Value; else if (e.ColumnIndex == databaseColumn.Index) importSettingsRow.ImportSettings.proteinDatabaseFilepath = (string) e.Value; else if (e.ColumnIndex == decoyPrefixColumn.Index) importSettingsRow.DecoyPrefix = (string) e.Value; else if (e.ColumnIndex == maxFDRColumn.Index && double.TryParse(e.Value.ToString(), out temp)) importSettingsRow.ImportSettings.maxQValue = Convert.ToDouble(e.Value); else if (e.ColumnIndex == maxRankColumn.Index) importSettingsRow.ImportSettings.maxResultRank = Convert.ToInt32(e.Value); else if (e.ColumnIndex == ignoreUnmappedPeptidesColumn.Index) importSettingsRow.ImportSettings.ignoreUnmappedPeptides = (bool) e.Value; else if (e.ColumnIndex == qonverterSettingsColumn.Index) importSettingsRow.QonverterSettingsPreset = (string) e.Value; } }
/// <summary> /// Create symbols and/or images /// </summary> /// <param name="e"></param> protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { if (expandedRowList == null) { base.OnCellPainting(e); return; } //Only paint in the first column of each info-containing row if (e.RowIndex < 0 || e.ColumnIndex != 0) { if (CellPainting != null) { var rowIndexHierarchy = e.RowIndex < 0 ? HeaderRowIndexHierarchy : expandedRowList[e.RowIndex].RowIndexHierarchy; var e2 = new TreeDataGridViewCellPaintingEventArgs(this, e, rowIndexHierarchy); CellPainting(this, e2); if (e2.Handled) { e.Handled = true; return; } } base.OnCellPainting(e); return; } var rowInfo = expandedRowList[e.RowIndex]; int nodeDepth = rowInfo.RowIndexHierarchy.Count - 1; int iconWidth = 0; if (CellPainting != null) { var e2 = new TreeDataGridViewCellPaintingEventArgs(this, e, rowInfo.RowIndexHierarchy); CellPainting(this, e2); if (e2.Handled) { e.Handled = true; return; } } e.Handled = true; //Still show selection if row is selected bool isSelected = (e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected; e.PaintBackground(e.CellBounds, isSelected); Point symbolPoint = GetSymbolPoint(e.CellBounds, nodeDepth); //Draw symbol if row is not in bottom node if (rowInfo.HasChildRows) { var symbol = rowInfo.ExpandedChildRows.Count > 0 ? ExpandedSymbol : CollapsedSymbol; var smoothingMode = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //Go through and actually draw the stored symbol var brush = new SolidBrush(isSelected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor); var pen = new Pen(brush); foreach (Symbol.Line line in symbol.Lines) { Point lineStart = line.Start, lineEnd = line.End; lineStart.Offset(symbolPoint.X, symbolPoint.Y); lineEnd.Offset(symbolPoint.X, symbolPoint.Y); e.Graphics.DrawLine(pen, lineStart, lineEnd); } e.Graphics.SmoothingMode = smoothingMode; } //Draw icon if one is selected if (CellIconNeeded != null) { var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, rowInfo.RowIndexHierarchy); CellIconNeeded(this, cellValueEventArgs); if (cellValueEventArgs.Value != null) { var icon = (Image)cellValueEventArgs.Value; e.Graphics.DrawImage(icon, symbolPoint.X + SymbolWidth + 5, symbolPoint.Y - 3, 15, 15); iconWidth = 20; //Indicates icon was drawn } } //Paint cell info, taking previous images into account var indentPadding = new Padding(symbolPoint.X - e.CellBounds.X + SymbolWidth + iconWidth + 2, 0, 0, 0); e.CellStyle.Padding = indentPadding; e.Paint(e.CellBounds, DataGridViewPaintParts.ContentForeground); }
private void getChildRowCount (AggregateRow row, Grouping<GroupBy> childGrouping, TreeDataGridViewCellValueEventArgs e) { if (childGrouping == null) { if (checkedGroupings.Any(o => o.Mode == GroupBy.Spectrum || o.Mode == GroupBy.Peptide)) e.HasChildRows = true; else e.ChildRowCount = row.PeptideSpectrumMatches; } else if (childGrouping.Mode == GroupBy.Source) { var dataFilter = row.DataFilter; if (dataFilter.SpectrumSourceGroup == null) { // create a filter from the cached root group for this data filter var nonGroupParentFilterKey = new DataFilterKey(dataFilter); var rootGroup = (getSpectrumSourceRows(dataFilter)[0] as SpectrumSourceGroupRow).SpectrumSourceGroup; dataFilter = new DataFilter(row.DataFilter) { SpectrumSourceGroup = new List<SpectrumSourceGroup>() { rootGroup } }; } e.ChildRowCount = getSpectrumSourceRows(dataFilter).Count; } else if (childGrouping.Mode == GroupBy.Spectrum) e.ChildRowCount = row.Spectra; else if (childGrouping.Mode == GroupBy.Analysis) e.ChildRowCount = row.DistinctAnalyses; else if (childGrouping.Mode == GroupBy.Peptide) e.ChildRowCount = row.DistinctPeptides; else if (childGrouping.Mode == GroupBy.Charge) e.ChildRowCount = row.DistinctCharges; else throw new NotImplementedException(); }
private void treeDataGridView_CellValueNeeded (object sender, TreeDataGridViewCellValueEventArgs e) { if (e.RowIndexHierarchy.First() >= rows.Count) { e.Value = null; return; } Row baseRow = GetRowFromRowHierarchy(e.RowIndexHierarchy); Grouping<GroupBy> childGrouping = null; if (baseRow is SpectrumSourceGroupRow) { var row = baseRow as SpectrumSourceGroupRow; var nonGroupParentFilterKey = new DataFilterKey(new DataFilter(row.DataFilter) { SpectrumSourceGroup = null }); var cachedRowsBySource = rowsBySource[nonGroupParentFilterKey]; e.ChildRowCount = cachedRowsBySource.OfType<SpectrumSourceGroupRow>() .Count(o => o.SpectrumSourceGroup.IsImmediateChildOf(row.SpectrumSourceGroup) /*&& (findTextBox.Text == "Find..." || o.SpectrumSourceGroup.Name.Contains(findTextBox.Text))*/); e.ChildRowCount += cachedRowsBySource.OfType<SpectrumSourceRow>() .Count(o => o.SpectrumSource.Group != null && o.SpectrumSource.Group.Id == row.SpectrumSourceGroup.Id /*&& (findTextBox.Text == "Find..." || o.SpectrumSource.Name.Contains(findTextBox.Text))*/); if (e.ChildRowCount == 0 && findTextBox.Text == "Find...") throw new InvalidDataException("no child rows for source group"); } else if (baseRow is SpectrumSourceRow) childGrouping = GroupingSetupControl<GroupBy>.GetChildGrouping(checkedGroupings, GroupBy.Source); else if (baseRow is SpectrumRow) childGrouping = GroupingSetupControl<GroupBy>.GetChildGrouping(checkedGroupings, GroupBy.Spectrum); else if (baseRow is AnalysisRow) childGrouping = GroupingSetupControl<GroupBy>.GetChildGrouping(checkedGroupings, GroupBy.Analysis); else if (baseRow is PeptideRow) childGrouping = GroupingSetupControl<GroupBy>.GetChildGrouping(checkedGroupings, GroupBy.Peptide); else if (baseRow is ChargeRow) childGrouping = GroupingSetupControl<GroupBy>.GetChildGrouping(checkedGroupings, GroupBy.Charge); else if (baseRow is PeptideSpectrumMatchRow) e.HasChildRows = true; if (!e.ChildRowCount.HasValue && baseRow is AggregateRow) getChildRowCount(baseRow as AggregateRow, childGrouping, e); e.Value = getCellValue(e.ColumnIndex, baseRow); }
private void treeDataGridView_CellIconNeeded (object sender, TreeDataGridViewCellValueEventArgs e) { if (e.RowIndexHierarchy.First() >= rows.Count) { e.Value = null; return; } Row baseRow = GetRowFromRowHierarchy(e.RowIndexHierarchy); if (baseRow is SpectrumSourceGroupRow) e.Value = Properties.Resources.XPfolder_closed; else if (baseRow is SpectrumSourceRow) e.Value = Properties.Resources.file; else if (baseRow is SpectrumRow) e.Value = Properties.Resources.SpectrumIcon; else if (baseRow is PeptideSpectrumMatchRow) e.Value = Properties.Resources.PSMIcon; else if (baseRow is PeptideRow) e.Value = Properties.Resources.Peptide; }
/// <summary> /// Show child rows /// </summary> /// <param name="index">Which row to expand</param> /// <param name="maxDepth">How far down to expand</param> /// <returns></returns> protected int expand (int index, int maxDepth) { var rowInfo = expandedRowList[index]; if (!rowInfo.HasChildRows || rowInfo.ExpandedChildRows.Count > 0 && maxDepth == 0) return 0; // row already expanded, nothing to do int rowsAdded = 0; if (rowInfo.ExpandedChildRows.Count == 0) { if (!rowInfo.ChildRowCount.HasValue) { var e = new TreeDataGridViewChildRowCountNeededEventArgs(rowInfo.RowIndexHierarchy); OnChildRowCountNeeded(e); rowInfo.ChildRowCount = e.ChildRowCount; } var childRowList = new List<ExpandedRowList>(rowInfo.ChildRowCount.Value); for (int j = 0; j < rowInfo.ChildRowCount; ++j) { //get the content of the child row and add it to list to be inserted var childRowInfo = new ExpandedRowList(rowInfo.RowIndexHierarchy, j); var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, childRowInfo.RowIndexHierarchy); CellValueNeeded(this, cellValueEventArgs); childRowInfo.ChildRowCount = cellValueEventArgs.ChildRowCount; childRowInfo.HasChildRows = cellValueEventArgs.HasChildRows; childRowList.Add(childRowInfo); } //insert new rows into table rowInfo.ExpandedChildRows = childRowList; expandedRowList.InsertRange(index + 1, childRowList); rowsAdded = childRowList.Count; } //If more expansion is needed recurse back to the begining if (maxDepth > rowInfo.RowIndexHierarchy.Count) for (int j = 0; j < rowInfo.ChildRowCount; ++j) rowsAdded += expand(index + rowsAdded + 1 - rowInfo.ChildRowCount.Value + j, maxDepth); return rowsAdded; }
protected override void OnCellValuePushed(DataGridViewCellValueEventArgs e) { if (CellValuePushed == null) return; // DataGridView may ask for cells after RowCount is set to 0 in order to commit changes if (expandedRowList == null || e.RowIndex >= expandedRowList.Count) return; //converts row number into hierarchy list, understandable by user-specified value-retrieval function var rowInfo = expandedRowList[e.RowIndex]; var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(e.ColumnIndex, rowInfo.RowIndexHierarchy); cellValueEventArgs.Value = e.Value; CellValuePushed(this, cellValueEventArgs); }
protected List<ExpandedRowList> expandedRowList; //keeps track of all nodes shown in table #region Overridden events protected override void OnCellValueNeeded (DataGridViewCellValueEventArgs e) { if (CellValueNeeded == null) throw new InvalidOperationException("TreeDataGridView requires at least one handler for CellValueNeeded"); // DataGridView may ask for cells after RowCount is set to 0 in order to commit changes if (expandedRowList == null || e.RowIndex >= expandedRowList.Count) return; //converts row number into hierarchy list, understandable by user-specified value-retrieval function var rowInfo = expandedRowList[e.RowIndex]; var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(e.ColumnIndex, rowInfo.RowIndexHierarchy); CellValueNeeded(this, cellValueEventArgs); e.Value = cellValueEventArgs.Value; if (e.ColumnIndex == 0) { rowInfo.ChildRowCount = cellValueEventArgs.ChildRowCount; rowInfo.HasChildRows = cellValueEventArgs.HasChildRows; } }