Beispiel #1
0
        //Clears GridView and Any Subscriptions
        private void EmptyGridView(string nameOfApp)
        {
            int index = App.GetFileNames().IndexOf(nameOfApp.ToLower());

            if (index < 0)
            {
                throw new Exception("Cannot find file \"" + nameOfApp + ".app\" in " + Settings.Default.DefaultPath);
            }
            AppParse = new AppParser(App.GetDirectoryNames()[index]);

            if (ViewData != null)
            {
                for (int j = 0; j < NewBalanceDataGridView.RowCount; j++)
                {
                    for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++)
                    {
                        if (ViewData.GetCellType(0, i) == CellType.Multiple)
                        {
                            MultipleCell mc = ViewData.GetCell(0, i) as MultipleCell;
                            mc.NotifyHeaderNameChange -= mc_NotifyHeaderNameChange;
                            mc.CellValueChanged       -= NewBalance_CellValueChanged;
                            mc.NotifyDependents       -= NewBalance_NotifyDependents;

                            foreach (var cell in mc.CellOptions)
                            {
                                cell.CellValueChanged -= NewBalance_CellValueChanged;
                                cell.NotifyDependents -= NewBalance_NotifyDependents;
                            }
                        }
                        else
                        {
                            Cell c = ViewData.GetCell(0, i);
                            c.CellValueChanged -= NewBalance_CellValueChanged;
                            c.NotifyDependents -= NewBalance_NotifyDependents;
                        }
                    }
                }

                // unfreeze any old frozen columns
                NewBalanceDataGridView.Columns[FindDisplayIndexColumnIndex(0)].Frozen = false;

                // make sure the actual index and viewindex are the same
                for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++)
                {
                    NewBalanceDataGridView.Columns[i].DisplayIndex = i;
                }
            }

            NewBalanceDataGridView.Rows.Clear();

            ViewData = new GridData(AppParse.ReturnCellsInRow(NewBalanceDataGridView.RowCount), nameOfApp);

            // update right click context menu if multiple cells exist
            RightClickMenu = new ContextMenuStrip();
            NewBalanceDataGridView.ContextMenuStrip = RightClickMenu;

            if (ViewData.HasMultipleCells())
            {
                for (int i = 0; i < ViewData.ColumnHeaders().Count; i++)
                {
                    var cell = ViewData.GetCell(0, i) as MultipleCell;
                    if (cell != null)
                    {
                        foreach (string s in cell.OptionStrings)
                        {
                            ToolStripMenuItem t = new ToolStripMenuItem(s);
                            t.Click += t_Click;
                            RightClickMenu.Items.Add(t);
                        }

                        break;
                    }
                }
            }

            List <string> columnHeaders = ViewData.ColumnHeaders();

            int count = columnHeaders.Count;

            NewBalanceDataGridView.ColumnCount    = count;
            NewBalanceDataGridView.CellBeginEdit += NewBalanceDataGridView_CellBeginEdit;
            NewBalanceDataGridView.CellEndEdit   += NewBalanceDataGridView_CellEndEdit;

            NewBalanceDataGridView.Rows.Add();

            for (int i = 0; i < count; i++)
            {
                NewBalanceDataGridView.Columns[i].HeaderText = columnHeaders[i];

                // hide newscreen cells (backwards compatibility)
                NewBalanceDataGridView.Columns[i].Visible =
                    !(NewBalanceDataGridView.Columns[i].HeaderText.ToLower().Contains("newscreen"));

                // set maxium input size (backwards compatibility)
                ((DataGridViewTextBoxColumn)NewBalanceDataGridView.Columns[i]).MaxInputLength =
                    ViewData.GetCell(0, i).Digits;

                NewBalanceDataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;

                NewBalanceDataGridView.Rows[0].Cells[i].Value = ViewData.GetCell(0, i).Value.ToString();

                //// set default formatting options
                //NewBalanceDataGridView.Columns[i].DefaultCellStyle.Format = "N" + ViewData.GetCell(0, i).Precision;
            }

            for (int i = 0; i < NewBalanceDataGridView.Rows[0].Cells.Count; i++)
            {
                if (ViewData.GetCellType(0, i) == CellType.Multiple)
                {
                    MultipleCell mc = ViewData.GetCell(0, i) as MultipleCell;
                    mc.NotifyHeaderNameChange += mc_NotifyHeaderNameChange;
                    mc.CellValueChanged       += NewBalance_CellValueChanged;
                    mc.NotifyDependents       += NewBalance_NotifyDependents;

                    foreach (var cell in mc.CellOptions)
                    {
                        cell.CellValueChanged += NewBalance_CellValueChanged;
                        cell.NotifyDependents += NewBalance_NotifyDependents;
                    }
                }
                else
                {
                    Cell c = ViewData.GetCell(0, i);
                    c.CellValueChanged += NewBalance_CellValueChanged;
                    c.NotifyDependents += NewBalance_NotifyDependents;
                }

                NewBalanceDataGridView.Columns[i].Resizable = DataGridViewTriState.True;
            }

            NewBalanceDataGridView.SelectionChanged += NewBalanceDataGridView_SelectionChanged;
        }