/// <summary> /// Raises the <see cref="E:System.Windows.Forms.DataGridView.RowEnter"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellEventArgs"></see> that contains the event data.</param> protected override void OnRowEnter(DataGridViewCellEventArgs e) { base.OnRowEnter(e); if (_root.Store == null) { return; } IMonitorSelectionService monitorSelectionService = (IMonitorSelectionService)((ModelElement)_root).Store.GetService(typeof(IMonitorSelectionService)); if (monitorSelectionService != null && e.RowIndex > 0) { ISelectionService selectionService = monitorSelectionService.CurrentSelectionContainer as ISelectionService; VirtualTreeGridItem value = GetRowValue(e.RowIndex); if (value != null && value.DataItem != null) { if (selectionService != null) { selectionService.SetSelectedComponents(new object[] { value.DataItem }); } } } }
/// <summary> /// Suppression d'une ligne /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void RowDelete_Click(object sender, EventArgs e) { VirtualTreeGridItem item = GetRowValue(_contextMenuRowIndex); OnDataChanged(new VirtualTreeGridDataChangedEventsArgs(item, true)); Rows.RemoveAt(_contextMenuRowIndex); }
/// <summary> /// Quand on commence à éditer une cellule, on supprime la sélection dans le diagramme pour être sur de capturer /// tous les événements /// (Pour corriger le BUG: Quand on appuie sur la touche DEL lors de l'édition d'une cellule, c'est le shape sélectionné qui disparait) /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellCancelEventArgs"></see> that contains the event data.</param> /// <exception cref="T:System.ArgumentOutOfRangeException">The value of the <see cref="P:System.Windows.Forms.DataGridViewCellCancelEventArgs.ColumnIndex"></see> property of e is greater than the number of columns in the control minus one.-or-The value of the <see cref="P:System.Windows.Forms.DataGridViewCellCancelEventArgs.RowIndex"></see> property of e is greater than the number of rows in the control minus one.</exception> protected override void OnCellBeginEdit(DataGridViewCellCancelEventArgs e) { base.OnCellBeginEdit(e); ModelElement elem = _root as ModelElement; // On enlève la sélection sur le shape if (elem != null) { IList <PresentationElement> shapes = PresentationViewsSubject.GetPresentation(elem); if (shapes.Count > 0) { NodeShape ns = shapes[0] as NodeShape; if (ns != null && ns.Diagram != null && ns.Diagram.ClientViews.Count > 0) { DiagramClientView clientView = ns.Diagram.ClientViews[0] as DiagramClientView; if (clientView != null) { clientView.Selection.Clear(); } } } } // L'entete n'est pas éditable ou une catégorie VirtualTreeGridItem item = GetRowValue(e.RowIndex); if (item == null || item.Kind == ModelKind.Root || item.Kind == ModelKind.Category) { e.Cancel = true; } _inPlaceEditMode = true; }
/// <summary> /// Sets the location and size of the editing panel hosted by the cell, and returns the normal bounds of the editing control within the editing panel. /// </summary> /// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"></see> that defines the cell bounds.</param> /// <param name="cellClip">The area that will be used to paint the editing panel.</param> /// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle"></see> that represents the style of the cell being edited.</param> /// <param name="singleVerticalBorderAdded">true to add a vertical border to the cell; otherwise, false.</param> /// <param name="singleHorizontalBorderAdded">true to add a horizontal border to the cell; otherwise, false.</param> /// <param name="isFirstDisplayedColumn">true if the cell is in the first column currently displayed in the control; otherwise, false.</param> /// <param name="isFirstDisplayedRow">true if the cell is in the first row currently displayed in the control; otherwise, false.</param> /// <returns> /// A <see cref="T:System.Drawing.Rectangle"></see> that represents the normal bounds of the editing control within the editing panel. /// </returns> /// <exception cref="T:System.InvalidOperationException">The cell has not been added to a <see cref="T:System.Windows.Forms.DataGridView"></see> control.</exception> public override Rectangle PositionEditingPanel(Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) { Rectangle rect = base.PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow); VirtualTreeGridItem value = OwningRow.DataBoundItem as VirtualTreeGridItem; Point pt = DataGridView.EditingPanel.Location; int decalage = 43; if (value != null) { if (value.Kind == ModelKind.Child) { decalage = 58; } } rect.Width -= decalage; pt.X += decalage; rect.X += decalage; DataGridView.EditingPanel.BackColor = Color.Transparent; //DataGridView.EditingPanel.Location = pt; //DataGridView.EditingPanel.Width -= decalage; return(rect); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.KeyPress"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.KeyPressEventArgs"></see> that contains the event data.</param> protected override void OnKeyPress(KeyPressEventArgs e) { base.OnKeyPress(e); VirtualTreeGridItem item = EditingControlDataGridView.Rows[EditingControlRowIndex].DataBoundItem as VirtualTreeGridItem; if (item != null) { if (item.Kind == ModelKind.Member) { string separators = ((VirtualTreeGrid)EditingControlDataGridView).MemberSeparators; if (separators.IndexOf(e.KeyChar) >= 0) { ((VirtualTreeGrid)EditingControlDataGridView).NavigateNext(EditingControlRowIndex, false); e.Handled = true; return; } } } if (item != null) { if (item.Kind == ModelKind.Child) { string separators = ((VirtualTreeGrid)EditingControlDataGridView).ChildSeparators; if (separators.IndexOf(e.KeyChar) >= 0) { ((VirtualTreeGrid)EditingControlDataGridView).NavigateNext(EditingControlRowIndex, e.KeyChar == ')'); e.Handled = true; return; } } } // La 1ère lettre ne peut pas être un chiffre if (Text.Length == 0 && Char.IsDigit(e.KeyChar)) { e.Handled = true; return; } // Caractères valides if (Char.IsLetterOrDigit(e.KeyChar) || e.KeyChar == '_' || Char.IsControl(e.KeyChar)) { return; } // Tous les autres sont incorrects e.Handled = true; }
/// <summary> /// Handles the Click event of the RowCopy control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void RowCopy_Click(object sender, EventArgs e) { VirtualTreeGridItem item = GetRowValue(_contextMenuRowIndex); ArrayList list = new ArrayList(); list.Add(item.DataItem); CopyCommand cc = new CopyCommand(((ModelElement)_root).Store, list); if (cc.Enabled && cc.Visible()) { cc.Exec(); } }
/// <summary> /// Gets the row value. /// </summary> /// <param name="index">The index.</param> /// <returns></returns> internal VirtualTreeGridItem GetRowValue(int index) { if (index < 0 || index >= Rows.Count) { return(null); } DataGridViewRow row = Rows[index]; if (row == null) { return(null); } VirtualTreeGridItem item = row.DataBoundItem as VirtualTreeGridItem; return(item); }
/// <summary> /// Paints the specified graphics. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="clipBounds">The clip bounds.</param> /// <param name="cellBounds">The cell bounds.</param> /// <param name="rowIndex">Index of the row.</param> /// <param name="elementState">State of the element.</param> /// <param name="value">The value.</param> /// <param name="formattedValue">The formatted value.</param> /// <param name="errorText">The error text.</param> /// <param name="cellStyle">The cell style.</param> /// <param name="advancedBorderStyle">The advanced border style.</param> /// <param name="paintParts">The paint parts.</param> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { VirtualTreeGridItem item = OwningRow.DataBoundItem as VirtualTreeGridItem; // On n'affiche pas la case à cocher if (item != null && (item.Kind == ModelKind.Root || item.Kind == ModelKind.Category)) { paintParts &= ~DataGridViewPaintParts.ContentForeground; } base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
/// <summary> /// Attaches and initializes the hosted editing control. /// </summary> /// <param name="rowIndex">The index of the cell's parent row.</param> /// <param name="initialFormattedValue">The initial value to be displayed in the control.</param> /// <param name="dataGridViewCellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle"></see> that determines the appearance of the hosted control.</param> /// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); VirtualTreeGridItem item = DataGridView.Rows[rowIndex].DataBoundItem as VirtualTreeGridItem; DataGridViewComboBoxEditingControl ctrl = DataGridView.EditingControl as DataGridViewComboBoxEditingControl; ctrl.SelectedText = string.Empty; if (item != null && item.DataItem is IArgument) { DataGridView.EditingControl.Enabled = true; ctrl.SelectedIndex = ctrl.FindStringExact(item.Direction); } else { DataGridView.EditingControl.Enabled = false; } }
/// <summary> /// Passage à la ligne d'en dessous /// </summary> /// <param name="rowIndex">Index de la ligne courante</param> /// <param name="forceMethod">if set to <c>true</c> [force method].</param> public void NavigateNext(int rowIndex, bool forceMethod) { // Recherche du type de la ligne suivante int nextIndex = rowIndex + 1; VirtualTreeGridItem value = GetRowValue(rowIndex); // Il n'y a plus rien, on ne peut pas descendre if (value == null) { return; } // Si c'est une catégorie, on la saute if (value.Kind == ModelKind.Category) { value = GetRowValue(++nextIndex); if (value == null) { return; } } // Le passage sur une ligne, la déploie automatiquement if (value.Kind == ModelKind.Member && value.Collapse) { ExpandCollapseRow(rowIndex, true); } if (value.Kind == ModelKind.Child && forceMethod) { nextIndex++; } // On passe à la cellule suivante ProcessTabKey(Keys.Tab); // Et on se met en mode édition ClearSelection(); if (nextIndex < Rows.Count) { SetSelectedCellCore(0, nextIndex, true); SetCurrentCellAddressCore(0, nextIndex, false, true, false); } }
/// <summary> /// Affichage du code /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellEventArgs"></see> that contains the event data.</param> /// <exception cref="T:System.ArgumentOutOfRangeException">The value of the <see cref="P:System.Windows.Forms.DataGridViewCellEventArgs.ColumnIndex"></see> property of e is greater than the number of columns in the control minus one.-or-The value of the <see cref="P:System.Windows.Forms.DataGridViewCellEventArgs.RowIndex"></see> property of e is greater than the number of rows in the control minus one.</exception> protected override void OnCellDoubleClick(DataGridViewCellEventArgs e) { base.OnCellDoubleClick(e); // Essaye d'afficher le code VirtualTreeGridItem item = GetRowValue(e.RowIndex); if (item == null) { return; } IShowCodeProperties data = _root as IShowCodeProperties; if (data != null && item.DataItem is IHasChildren) { Mapper.Instance.ShowCode(_root.Id, data.Name, data.GetMemberName(item.DataItem.Name)); } }
/// <summary> /// On rentre en mode édition. /// </summary> /// <param name="rowIndex"></param> /// <param name="initialFormattedValue"></param> /// <param name="dataGridViewCellStyle"></param> public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); ComboBox comboBox = base.DataGridView.EditingControl as ComboBox; if (comboBox != null) { comboBox.DropDownStyle = ComboBoxStyle.DropDown; VirtualTreeGridItem value = OwningRow.DataBoundItem as VirtualTreeGridItem; comboBox.Enabled = (value != null && !value.IsNewValue); if (comboBox.Enabled) { //if( !comboBox.Items.Contains( value.Type ) ) // comboBox.Items.Add( value.Type ); //comboBox.SelectedIndex = comboBox.FindString( value.Type ); comboBox.Text = value.Type; } } }
/// <summary> /// Ouverture ou fermeture d'une branche /// </summary> /// <param name="rowIndex">Index de la branche</param> /// <param name="expand">true pour l'ouverture</param> private void ExpandCollapseRow(int rowIndex, bool expand) { SuspendLayout(); VirtualTreeGridItem methodValue = GetRowValue(rowIndex); // Est ce qu'on est sur une ligne qui peut s'ouvrir if (methodValue != null && methodValue.Kind == ModelKind.Member) { int index = rowIndex + 1; VirtualTreeGridItem value = GetRowValue(index); // L'affichage des enfants se fait en rendant leurs propriétés visible à true while (value != null && value.Kind == ModelKind.Child) { Rows[index].Visible = expand; value = GetRowValue(++index); } methodValue.Collapse = !expand; } ResumeLayout(); }
/// <summary> /// Initializes a new instance of the <see cref="VirtualTreeGridDataChangedEventsArgs"/> class. /// </summary> /// <param name="item">The item.</param> /// <param name="delete">if set to <c>true</c> [delete].</param> public VirtualTreeGridDataChangedEventsArgs(VirtualTreeGridItem item, bool delete) { _isDelete = delete; _item = item; }
/// <summary> /// Initializes a new instance of the <see cref="VirtualTreeGridDataChangedEventsArgs"/> class. /// </summary> /// <param name="item">The item.</param> public VirtualTreeGridDataChangedEventsArgs(VirtualTreeGridItem item) : this(item, false) { }
/// <summary> /// Handles the ExpandCollapse event of the colName control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.DataGridViewCellEventArgs"/> instance containing the event data.</param> private void colName_ExpandCollapse(object sender, DataGridViewCellEventArgs e) { VirtualTreeGridItem methodValue = GetRowValue(e.RowIndex); ExpandCollapseRow(e.RowIndex, methodValue.Collapse); }
/// <summary> /// Refreshes the data. /// </summary> private void RefreshData() { _members = new DataList(); _colName.HeaderName = _title; // Remplissage de la liste des types _colType.Items.Clear(); foreach (string typeName in _component.GetDefinedTypeNames()) { _colType.Items.Add(typeName); } // La racine VirtualTreeGridItem item = new VirtualTreeGridItem(_root); _members.Add(item); foreach (VirtualTreeGridCategory category in _categories) { // On ne met rien si il n'y a qu'une catégorie par défaut if (!category.IsEmpty) { _members.Add( new VirtualTreeGridItem(new VirtualCategoryInstance(category.Name), category, ModelKind.Category)); } IList operations = _root.GetChildrenForCategory(category); if (operations != null) { foreach (ITypeMember operation in operations) { _members.Add(new VirtualTreeGridItem(category, _root, operation, ModelKind.Member)); if (operation is IHasChildren) { IList arguments = ((IHasChildren)operation).GetChildrenForCategory(null); if (arguments != null) { foreach (ITypeMember arg in arguments) { _members.Add( new VirtualTreeGridItem(category, (IHasChildren)operation, arg, ModelKind.Child)); } // Un vide pour pouvoir en rajouter _members.Add( new VirtualTreeGridItem(category, (IHasChildren)operation, ModelKind.Child)); } } } // Un vide pour pouvoir en rajouter if (!category.ReadOnly) { _members.Add(new VirtualTreeGridItem(category, _root, ModelKind.Member)); } } DataSource = _members; foreach (DataGridViewRow row in Rows) { VirtualTreeGridItem data = (VirtualTreeGridItem)row.DataBoundItem; if (data.Kind == ModelKind.Member) { ExpandCollapseRow(row.Index, false); } row.ReadOnly = data.ReadOnly; } } }
/// <summary> /// Affichage d'une ligne. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="clipBounds">The clip bounds.</param> /// <param name="cellBounds">The cell bounds.</param> /// <param name="rowIndex">Index of the row.</param> /// <param name="cellState">State of the cell.</param> /// <param name="value">The value.</param> /// <param name="formattedValue">The formatted value.</param> /// <param name="errorText">The error text.</param> /// <param name="cellStyle">The cell style.</param> /// <param name="advancedBorderStyle">The advanced border style.</param> /// <param name="paintParts">The paint parts.</param> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Une ligne peut contenir des icones en début de ligne VirtualTreeGridItem item = DataGridView.Rows[rowIndex].DataBoundItem as VirtualTreeGridItem; if (item == null) { return; } // Décalage de la zone d'affichage pour libérer de la place pour les icones if (item.Kind == ModelKind.Member) { cellStyle.Padding = new Padding(43, 0, 0, 0); } if (item.Kind == ModelKind.Child) { cellStyle.Padding = new Padding(58, 0, 0, 0); } Color oldForeColor = cellStyle.ForeColor; // Entete en gras if (item.Kind == ModelKind.Root) { cellStyle.ForeColor = Color.Black; cellStyle.Font = new Font(cellStyle.Font, FontStyle.Bold); formattedValue = ((DataGridViewNameColumn)OwningColumn).HeaderName; } else if (item.Kind == ModelKind.Category) { cellStyle.ForeColor = Color.Gray; cellStyle.Font = new Font(cellStyle.Font, FontStyle.Bold | FontStyle.Italic); cellStyle.Padding = new Padding(20, 0, 0, 0); } else if (Utils.StringCompareEquals((string)formattedValue, item.EmptyName)) { cellStyle.ForeColor = Color.Black; cellStyle.Font = new Font(cellStyle.Font, FontStyle.Italic); } cellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; // Affichagedu texte base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); cellStyle.ForeColor = oldForeColor; // Zone de click hitRect = Rectangle.Empty; VirtualTreeGridItem nextItem = null; try { nextItem = rowIndex == DataGridView.Rows.Count - 1 ? null : DataGridView.Rows[rowIndex + 1].DataBoundItem as VirtualTreeGridItem; } catch { // Dans le cas ou la dernière ligne ne contient pas de données } bool lastCategoryRow = nextItem == null || nextItem.Kind != item.Kind; // Affichage des icones if (item.Kind == ModelKind.Category) { if (item.Category.Icon != null) { Point pt = cellBounds.Location; pt.X += 2; Bitmap bmp = item.Category.Icon; bmp.MakeTransparent(); graphics.DrawImage(bmp, pt); } } else if (item.Kind == ModelKind.Member) { Point pt = cellBounds.Location; pt.X += 6; Bitmap bmp; if (item.DataItem is IHasChildren) { bmp = lastCategoryRow ? VirtualTreeGridResource.CollapsedEnd : VirtualTreeGridResource.Collapsed; if (!item.Collapse) { bmp = VirtualTreeGridResource.Expanded; } bmp.MakeTransparent(); graphics.DrawImage(bmp, pt); // Sauvegarde de la zone de click hitRect = new Rectangle(pt, bmp.Size); pt.X += bmp.Width; } else { pt.X += 16; } bmp = VirtualTreeGridResource.VSObject_Method; pt.Y += (cellBounds.Height - bmp.Height) / 2; bmp.MakeTransparent(); graphics.DrawImage(bmp, pt); } else if (item.Kind == ModelKind.Child) { Point pt = cellBounds.Location; pt.X += 6; Bitmap bmp = VirtualTreeGridResource.VerticalLine; bmp.MakeTransparent(); graphics.DrawImage(bmp, pt); bmp = lastCategoryRow ? VirtualTreeGridResource.ArgumentVerticalLineEnd : VirtualTreeGridResource.ArgumentVerticalLine; bmp.MakeTransparent(); pt.X += 22; graphics.DrawImage(bmp, pt); Rectangle rect = cellBounds; rect.X = pt.X + 20; rect.Width = 16; VirtualTreeGridItem prevItem = DataGridView.Rows[rowIndex - 1].DataBoundItem as VirtualTreeGridItem; if (prevItem != null) { bool firstCategoryRow = prevItem.Kind != item.Kind; string prefix = ","; if (lastCategoryRow && firstCategoryRow) { prefix = "()"; } else if (lastCategoryRow) { prefix = ")"; } else if (firstCategoryRow) { prefix = "("; } Font font = new Font(cellStyle.Font, FontStyle.Bold | FontStyle.Regular); TextRenderer.DrawText(graphics, prefix, font, rect, cellStyle.ForeColor); } } }
/// <summary> /// Quand la cellule pert le focus, on ajoute une ligne /// en dessous suivant le contexte si c'est possible /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellEventArgs"></see> that contains the event data.</param> /// <exception cref="T:System.ArgumentOutOfRangeException">The value of the <see cref="P:System.Windows.Forms.DataGridViewCellEventArgs.ColumnIndex"></see> property of e is greater than the number of columns in the control minus one.-or-The value of the <see cref="P:System.Windows.Forms.DataGridViewCellEventArgs.RowIndex"></see> property of e is greater than the number of rows in the control minus one.</exception> protected override void OnCellValidated(DataGridViewCellEventArgs e) { base.OnCellValidated(e); try { // 1 ére ligne (Entete) if (e.RowIndex == 0 || _root == null || _root.Store == null) { return; } // Si on est sur une catégorie, on ne fait toujours rien VirtualTreeGridItem value = GetRowValue(e.RowIndex); // Si le nom saisie n'est pas valable ou si on est en readonly, on ne valide pas if (value == null || value.ReadOnly || String.IsNullOrEmpty(value.Name) || !StrategyManager.GetInstance(_root.Store).NamingStrategy.IsClassNameValid(value.Name)) { return; } bool isNewValue = value.IsNewValue; // Est on sur une ligne nouvelle ? // Vérification si l'utilisateur peut sortir de la cellule VirtualTreeGridDataChangedEventsArgs arg = new VirtualTreeGridDataChangedEventsArgs(value); OnDataChanged(arg); if (arg.Cancel) { return; } // Si on était sur la 1ère colonne, création d'une ligne supplémentaire if (e.ColumnIndex == 0) { if (isNewValue) { if (value.Kind == ModelKind.Member) { //VirtualTreeGridItem methodValue = value as VirtualTreeGridItem; if (value.DataItem is IHasChildren) { value.Collapse = false; _members.Add( new VirtualTreeGridItem(value.Category, (IHasChildren)value.DataItem, ModelKind.Child)); } _members.Add(new VirtualTreeGridItem(value.Category, value.Parent, ModelKind.Member)); if (value.DataItem is IHasChildren) { ExpandCollapseRow(Rows.Count - 2, false); } } else if (value.Kind == ModelKind.Child) { //VirtualTreeGridItem argValue = value as VirtualTreeGridItem; _members.Insert(e.RowIndex + 1, new VirtualTreeGridItem(value.Category, value.Parent, ModelKind.Child)); } } } } finally { _inPlaceEditMode = false; } }
/// <summary> /// Affichage du menu contextuel /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewRowContextMenuStripNeededEventArgs"></see> that contains the event data.</param> protected override void OnRowContextMenuStripNeeded(DataGridViewRowContextMenuStripNeededEventArgs e) { base.OnRowContextMenuStripNeeded(e); if (e.RowIndex > 0) { VirtualTreeGridItem data = GetRowValue(e.RowIndex); if (data == null || data.Kind == ModelKind.Root || data.Kind == ModelKind.Category) { return; } e.ContextMenuStrip = new ContextMenuStrip(); _contextMenuRowIndex = e.RowIndex; // Ajout de l'option de suppression ToolStripItem item = new ToolStripMenuItem("Copy"); item.Enabled = data.DataItem != null; item.Click += RowCopy_Click; e.ContextMenuStrip.Items.Add(item); //if (e.RowIndex > 1 && data.DataItem != null) //{ // item = new ToolStripMenuItem("Up"); // item.Enabled = true; // item.Click += new EventHandler(RowUp_Click); // e.ContextMenuStrip.Items.Add(item); //} // Recherche si on est sur la dernière ligne //if( data.DataItem != null) //{ // bool lastRow = true; // if (data.Kind == ModelKind.Child ) // { // VirtualTreeGridItem d = GetRowValue(e.RowIndex+1); // lastRow = d == null || d.DataItem == null; // } // else if (data.Kind == ModelKind.Member) // { // // En dessous d'un membre, il ne doit y avoir que des arguments ou des lignes vides. // // Si on rencontre autre chose, c'est qu'on est pas la dernière ligne // for (int i = e.RowIndex + 1; i < this.Rows.Count; i++) // { // VirtualTreeGridItem d = GetRowValue(i); // if (d != null && (d.Kind != ModelKind.Child && d.DataItem != null)) // { // lastRow = false; // break; // } // } // } // if (lastRow) // { // item = new ToolStripMenuItem("Down"); // item.Enabled = true; // item.Click += new EventHandler(RowDown_Click); // e.ContextMenuStrip.Items.Add(item); // } //} if (!data.ReadOnly) { item = new ToolStripMenuItem("Delete"); item.Enabled = data.DataItem != null; item.Click += RowDelete_Click; e.ContextMenuStrip.Items.Add(item); } } }