public static void RowHeaderInsertRow(object sender, DBTableControl.DBEditorTableControl mainTable) { if (!mainTable.ReadOnly && sender is MenuItem) { // Double check that whant triggered the event is what we expect. if ((sender as MenuItem).DataContext is DataRowView) { // Determine visual and data index of calling row. int datarowindex = mainTable.dbDataGrid.Items.IndexOf(((sender as MenuItem).DataContext as DataRowView)); mainTable.InsertRow(datarowindex); } else { // We'll end up here if the user is attempting to insert a row in front of the blank row, so we will simply add a new row // at the end of the table, still we'll use a try block in case something unforseen happens. try { mainTable.InsertRow(); } catch (Exception ex) { #if DEBUG ErrorDialog.ShowDialog(ex); #endif } } } }
public static void RowHeaderInsertManyRows(object sender, DBTableControl.DBEditorTableControl mainTable) { if (!mainTable.ReadOnly && sender is MenuItem) { // Request how many rows should be inserted from the user. InputBox insertrowsInputBox = new InputBox(); insertrowsInputBox.ShowDialog(); // Double check that whant triggered the event is what we expect. if (insertrowsInputBox.DialogResult == System.Windows.Forms.DialogResult.OK) { // Determine how many rows the user wants to add. int numrows = 0; try { numrows = int.Parse(insertrowsInputBox.Input); } catch (Exception ex) { if (ex is FormatException) { MessageBox.Show(String.Format("Input: {0}, is not a valid number of rows, please enter a whole number.", insertrowsInputBox.Input)); } else { #if DEBUG ErrorDialog.ShowDialog(ex); #endif } } for (int i = 0; i < numrows; i++) { DataRow newrow = mainTable.CurrentTable.NewRow(); if ((sender as MenuItem).DataContext is DataRowView) { mainTable.InsertRow(i); } else { try { // If the blank row is calling us, add to the end of the table. mainTable.InsertRow(); } catch (Exception ex) { #if DEBUG ErrorDialog.ShowDialog(ex); #endif } } } mainTable.UpdateVisibleRows(); mainTable.dbDataGrid.Items.Refresh(); } } }