Exemple #1
0
        // Logic Value Changed Event Handler
        void NewBalance_CellValueChanged(object sender, PropertyChangedEventArgs e)
        {
            Cell c = sender as Cell;

            if (e.PropertyName == "String")
            {
                if (sender is KCell)
                {
                    KCell k = sender as KCell;

                    if (k.KValue != String.Empty)
                    {
                        NewBalanceDataGridView.Rows[k.RowIndex].Cells[k.ColumnIndex].Value = k.KValue;
                    }
                    else
                    {
                        NewBalanceDataGridView.Rows[k.RowIndex].Cells[k.ColumnIndex].Value = k.Value.ToString();
                    }
                }
                else if (sender is MCell)
                {
                    MCell m = sender as MCell;
                    NewBalanceDataGridView.Rows[m.RowIndex].Cells[m.ColumnIndex].Value = m.MValue;
                }
            }
            else
            {
                if (c != null && c.Value == null)
                {
                    if (c is KCell)
                    {
                        KCell kc = c as KCell;

                        if (kc.KValue != String.Empty)
                        {
                            NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = kc.KValue;
                        }
                        else
                        {
                            NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null;
                        }
                    }
                    else if (c is MultipleCell)
                    {
                        MultipleCell mc = c as MultipleCell;

                        if (mc.SelectedValue != null)
                        {
                            NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = mc.SelectedValue;
                        }
                        else
                        {
                            NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null;
                        }
                    }
                    else
                    {
                        NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null;
                    }
                }
                else
                {
                    if (c != null)
                    {
                        // need to check if there is a calculation with sender as a dependency
                        ViewData.CheckAndUpdateDependency(c);
                        NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = c.Value.ToString();

                        if (ViewData.HasMultipleCells())
                        {
                            MultipleCell mc = null;

                            for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++)
                            {
                                if (ViewData.GetCellType(c.RowIndex, i) == CellType.Multiple)
                                {
                                    mc = ViewData.GetCell(c.RowIndex, i) as MultipleCell;
                                    break;
                                }
                            }

                            if (mc == null)
                            {
                                return;
                            }
                            // Update Value to the currently selected cell
                            ViewData.CheckAndUpdateMultipleDependency(c, mc);

                            if (mc.ColumnIndex == c.ColumnIndex && mc.RowIndex == c.RowIndex)
                            {
                                NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value =
                                    mc.SelectedValue.ToString();
                            }
                        }
                    }
                }
            }
        }