public static void ColumnApplyExpression(object sender, DBTableControl.DBEditorTableControl mainTable)
        {
            DataGridColumn col     = (((sender as MenuItem).Parent as ContextMenu).PlacementTarget as DataGridColumnHeader).Column;
            string         colname = (string)col.Header;

            ApplyExpressionWindow getexpwindow = new ApplyExpressionWindow();

            getexpwindow.ShowDialog();

            if (getexpwindow.DialogResult != null && (bool)getexpwindow.DialogResult)
            {
                for (int i = 0; i < mainTable.CurrentTable.Rows.Count; i++)
                {
                    // Skip any filtered rows, or any rows with an error in the column we are computing.
                    mainTable.UpdateVisibleRows();
                    if (mainTable._visibleRows[i] == System.Windows.Visibility.Collapsed ||
                        mainTable._errorList.Count(n => n.RowIndex == i && n.ColumnName.Equals(colname)) > 0)
                    {
                        continue;
                    }

                    // Grab the given expression, modifying it for each cell.
                    string expression = getexpwindow.EnteredExpression.Replace("x", string.Format("{0}", mainTable.CurrentTable.Rows[i][colname]));
                    object newvalue   = mainTable.CurrentTable.Compute(expression, "");
                    int    colindex   = mainTable.CurrentTable.Columns.IndexOf(colname);

                    // For integer based columns, do a round first if necessary.
                    if (mainTable.EditedFile.CurrentType.Fields[colindex].TypeCode == TypeCode.Int32 ||
                        mainTable.EditedFile.CurrentType.Fields[colindex].TypeCode == TypeCode.Int16)
                    {
                        int newintvalue;
                        if (!Int32.TryParse(newvalue.ToString(), out newintvalue))
                        {
                            double tempvalue = Double.Parse(newvalue.ToString());
                            tempvalue   = Math.Round(tempvalue, 0);
                            newintvalue = (int)tempvalue;
                        }

                        newvalue = newintvalue;
                    }
                    mainTable.CurrentTable.Rows[i][colname] = newvalue;
                }
            }

            mainTable.RefreshColumn(mainTable.dbDataGrid.Columns.IndexOf(col));
        }
        public static void RenumberMenuItem(object sender, DBTableControl.DBEditorTableControl mainTable)
        {
            // Get the column index this context menu was called from.
            DataGridColumn col            = (((sender as MenuItem).Parent as ContextMenu).PlacementTarget as DataGridColumnHeader).Column;
            string         colname        = (string)col.Header;
            List <int>     visualroworder = new List <int>();

            InputBox renumberInputBox = new InputBox {
                Text = "Re-Number from", Input = "1"
            };

            if (renumberInputBox.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    int parsedNumber = int.Parse(renumberInputBox.Input);
                    for (int i = 0; i < mainTable.dbDataGrid.Items.Count; i++)
                    {
                        // Skip any non DataRowView, which should only be the blank row at the bottom.
                        if (!(mainTable.dbDataGrid.Items[i] is DataRowView))
                        {
                            continue;
                        }
                        // Store the data row index associated with the current visual row to account for column sorting.
                        visualroworder.Add(mainTable.CurrentTable.Rows.IndexOf((mainTable.dbDataGrid.Items[i] as DataRowView).Row));
                    }

                    // Now that we have a set order, we can assign values.
                    for (int i = 0; i < visualroworder.Count; i++)
                    {
                        mainTable.CurrentTable.Rows[visualroworder[i]][colname] = parsedNumber + i;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Could not apply values: {0}", ex.Message), "You fail!");
                }
            }

            mainTable.RefreshColumn(mainTable.dbDataGrid.Columns.IndexOf(col));
        }