//INSTANT C# NOTE: C# does not support optional parameters. Overloaded method(s) are created above. //ORIGINAL LINE: Public Shared Function deleteSelectedTrVwItem(ByVal TreeView As TreeView, Optional ByVal callback As BeforeDeleteCallback = null) As Integer public static int deleteSelectedTrVwItem(TreeView TreeView, BeforeDeleteCallback callback) { TreeNode node = TreeView.SelectedNode; // proteger contra o caso não existir um nó selecionado // e impedir a remoção dos items não editáveis if (node == null || node.Tag == null) { return(-1); } switch (MessageBox.Show("Tem a certeza que deseja " + "eliminar o(s) item(s) selecionado(s)?", "Eliminar item", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)) { case DialogResult.OK: ((DataRow)node.Tag).Delete(); node.Remove(); //TreeView.SelectedNode = Nothing return((int)DialogResult.OK); case DialogResult.Cancel: // do nothing return((int)DialogResult.Cancel); } //INSTANT C# NOTE: Inserted the following 'return' since all code paths must return a value in C#: return(0); }
public static void deleteSelectedLstVwItems(ListView ListView, BeforeDeleteCallback callback, Type undeletableType) { if (ListView.SelectedItems.Count == 0) { return; } string TitleMsgBox = "Remoção de item(s)"; string AditionalMsg = string.Empty; int NonDeletableItemsCount = 0; foreach (ListViewItem item in ListView.SelectedItems) { if ((undeletableType == null && item.Tag == null) || (undeletableType != null && undeletableType.IsInstanceOfType(item.Tag))) { if (AditionalMsg.Length == 0) { AditionalMsg = System.Environment.NewLine + "Existe pelo menos um item que não poderá " + "ser removido, serão removidos apenas os restantes."; } NonDeletableItemsCount = NonDeletableItemsCount + 1; } } // se todos os items forem não editáveis não vale a pela prosseguir if (NonDeletableItemsCount == ListView.SelectedItems.Count) { if (ListView.SelectedItems.Count == 1) { MessageBox.Show("O item selecionado não pode ser removido.", TitleMsgBox, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("Os items selecionados não podem ser removidos.", TitleMsgBox, MessageBoxButtons.OK, MessageBoxIcon.Warning); } return; } switch (MessageBox.Show("Tem a certeza que deseja " + "eliminar o(s) item(s) selecionado(s)?" + AditionalMsg, TitleMsgBox, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)) { case DialogResult.OK: //Get and delete the selected rows foreach (ListViewItem item in ListView.SelectedItems) { if (!(undeletableType == null && item.Tag == null) && !(undeletableType != null && undeletableType.IsInstanceOfType(item.Tag))) { if (callback != null) { callback((DataRow)item.Tag); } ((DataRow)item.Tag).Delete(); item.Remove(); } } break; case DialogResult.Cancel: // do nothing break; } }
public static void deleteSelectedLstVwItems(ListView ListView, BeforeDeleteCallback callback) { deleteSelectedLstVwItems(ListView, callback, null); }