示例#1
0
        private void menuDeleteObj_Click(object sender, EventArgs e)
        {
            if (dataGrid1.CurrentRow == null)
            {
                return;
            }

            if (showWarning)
            {
                var dr = MessageBox.Show("This will permanently delete the selected row/object.\n\nAre you sure?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.No)
                {
                    return;
                }

                showWarning = false; // User has been warned
            }

            var i    = dataGrid1.CurrentRow.Index;
            var name = dataGrid1[3, i].Value.ToString();
            var obj  = GetNewObject(name);

            MapInterface.ObjectRemove(obj);

            dataGrid1.Rows.RemoveAt(i);
            UpdateFilter();
            if (dataGrid1.Rows.Count > i)
            {
                if (dataGrid1.Rows[i].Visible)
                {
                    dataGrid1.CurrentCell = dataGrid1.Rows[i].Cells[3];
                }
                else
                {
                    if (GetNumRowsVisible() > 0)
                    {
                        dataGrid1.CurrentCell = dataGrid1.Rows[dataGrid1.Rows.GetLastRow(DataGridViewElementStates.Visible)].Cells[3];
                    }
                }
            }

            MainWindow.Instance.mapView.MapRenderer.UpdateCanvas(true, true);
        }