public void _grid_SelectionChangedComedata(string addre,string ro,string co )
        {
            string address = null;
            string text = null;
            string status = "Ready";
            int row =Convert.ToInt32( ro);
            int col = Convert.ToInt32(co);
              // DGV[row, col].Value = addre;
            DGV.Rows[row].Cells[col].Value = addre;
            if (row > -1 && col > -1)
            {
                var cell = "";
                if(DGV.Rows.Count>0)
                 cell = DGV.Rows[row].Cells[col].ToString();

               // var val = cell.Value;
                var val = addre;
                text = val != null ? val.ToString() : null;
                address = DGV.GetAddress(row, col);
                var selection = new CellRange(DGV.SelectedCells);
                if (!selection.IsSingleCell)
                {
                    var sel = DGV.GetAddress(selection);
                    try
                    {
                        var avg = DGV.Evaluate(string.Format("Average({0})", sel));
                        var count = DGV.Evaluate(string.Format("Count({0})", sel));
                        var sum = DGV.Evaluate(string.Format("Sum({0})", sel));
                        if ((double)count > 0)
                        {
                            status = string.Format("Average: {0:#,##0.##} Count: {1:n0} Sum: {2:#,##0.##}",
            avg, count, sum);
                        }
                    }
                    catch
                    {
                        // the selection contains errors...
                    }
                }
            }
            _lblAddress.Text = address;
            _txtFormula.Text = text;
            _txtFormula.SelectAll();
            _lblStatus.Text = status;
            if (text == "=")
            {
             //   Calculation ca = new Calculation();
                List<string> SelectedRows = new List<string>();
                foreach (DataGridViewColumn _dc in DGV.Columns)
                {
                    if (_dc.Visible == false)
                    {
                        //  MessageBox.Show("Column Name " + _dc.Name + " Visible " + _dc.Visible);

                        // SelectedRows.Add(_dc.Name.ToString());

                    }
                    else
                    {

                        SelectedRows.Add(_dc.Name.ToString());
                    }
                }

                List<string> Selectedcolumn = new List<string>();

                // foreach (DataGridViewRow _dcc in DGV.Rows[0].Cells)
                foreach (DataGridViewRow _dcc in DGV.Rows)
                {
                    String data = "";
                    data = Convert.ToString(_dcc.Cells[1].Value);
                    // data = _dcc.Cells[1].Value.ToString();
                    if (data == "")
                    {

                    }
                    //  MessageBox.Show("Column Name Visible " + _dcc.Name.ToString());
                    //  Selectedcolumn.Add ( _dcc.Cells[1].Value.ToString());
                    //MessageBox.Show("Column Name Visible " + _dcc.Visible);
                    Selectedcolumn.Add(data);

                }

                //for (int i = 0; i <= _table.Columns.Count; i++)
                //{

                //    string a = Convert.ToString(i);

                //}

                // DGV.Columns("DescriptionB").Selected = true;
                // DGV.Rows(intIndex).Selected = true;
                // ca.Show();
              //  ca.sho(SelectedRows, Selectedcolumn, row, col);

              //  ca.Show();
            }
        }
Beispiel #2
0
 // gets the address of a cell range using Excel notation (e.g. A1:B10)
 public string GetAddress(CellRange rng)
 {
     return rng.IsSingleCell
         ? GetAddress(rng.r1, rng.c1)
         : string.Format("{0}:{1}", GetAddress(rng.r1, rng.c1), GetAddress(rng.r2, rng.c2));
 }
        void _grid_SelectionChanged(object sender, EventArgs e)
        {
            String se = "";
              //  se = DGV.SelectedCells[0].Value.ToString();
             //   var spp = DGV.Rows[row-1].Cells[col-1].Value;
               // var sev = DGV.Rows[row].Cells[col];
            // show cell content above grid

            string address = null;
            string text = null;
            string status = "Ready";

            row = DGV.CurrentCellAddress.Y;
            col = DGV.CurrentCellAddress.X;

            if (row > -1 && col > -1)
            {
                var cell = DGV.Rows[row].Cells[col];

                var val = cell.Value;
                text = val != null ? val.ToString() : null;
                address = DGV.GetAddress(row, col);
                var selection = new CellRange(DGV.SelectedCells);
                if (!selection.IsSingleCell)
                {
                    var sel = DGV.GetAddress(selection);
                    try
                    {
                        var avg = DGV.Evaluate(string.Format("Average({0})", sel));
                        var count = DGV.Evaluate(string.Format("Count({0})", sel));
                        var sum = DGV.Evaluate(string.Format("Sum({0})", sel));
                        if ((double)count > 0)
                        {
                            status = string.Format("Average: {0:#,##0.##} Count: {1:n0} Sum: {2:#,##0.##}",
                                avg, count, sum);
                        }
                    }
                    catch
                    {
                        // the selection contains errors...
                    }
                }
            }

            _lblAddress.Text = address;

            _txtFormula.Text = text;
            _txtFormula.SelectAll();
            _lblStatus.Text = status;
            if (text == "=")
            {
            //  CalcEngine.  Calculation ca = new Calculation();
                List<string> SelectedRows = new List<string>();
                foreach (DataGridViewColumn _dc in DGV.Columns)
                {
                    if (_dc.Visible == false)
                    {

                        //  MessageBox.Show("Column Name " + _dc.Name + " Visible " + _dc.Visible);
                        // SelectedRows.Add(_dc.Name.ToString());
                    }
                    else
                    {
                        SelectedRows.Add(_dc.Name.ToString());
                    }
                }
                List<string> Selectedcolumn = new List<string>();
                List<int> _Selectrowcount = new List<int>();
                foreach (DataGridViewRow _dcc in DGV.Rows)
                {
                    int a = 0;
                    for (int i = 0; i < DGV.RowCount; i++)
                    {
                        a = i;
                    }

                    _Selectrowcount.Add(a);

                    String data = "";
                    data = Convert.ToString(_dcc.Cells[1].Value);

                    if (data == "")
                    {

                    }

                    Selectedcolumn.Add(data);

                }

                //for (int i = 0; i <= _table.Columns.Count; i++)
                //{

                //    string a = Convert.ToString(i);

                //}

                // DGV.Columns("DescriptionB").Selected = true;
                // DGV.Rows(intIndex).Selected = true;
                // ca.Show();
            //    ca.sho(SelectedRows, Selectedcolumn, row, col);

             //   ca.Show();
            }
        }
Beispiel #4
0
 // ** implementation
 object GetValue(CellRange rng)
 {
     if (_evaluating)
     {
         throw new Exception("Circular Reference");
     }
     try
     {
         _evaluating = true;
         return _grid.Evaluate(rng.r1, rng.c1);
     }
     finally
     {
         _evaluating = false;
     }
 }
Beispiel #5
0
 // ** IEnumerable
 public IEnumerator GetEnumerator()
 {
     for (int r = _rng.TopRow; r <= _rng.BottomRow; r++)
     {
         for (int c = _rng.LeftCol; c <= _rng.RightCol; c++)
         {
             var rng = new CellRange(r, c);
             yield return GetValue(rng);
         }
     }
 }
Beispiel #6
0
 // ** ctor
 public CellRangeReference(DataGridCalc grid, CellRange rng)
 {
     _grid = grid;
     _rng = rng;
 }
Beispiel #7
0
 CellRange MergeRanges(CellRange rng1, CellRange rng2)
 {
     return new CellRange(
         Math.Min(rng1.TopRow, rng2.TopRow),
         Math.Min(rng1.LeftCol, rng2.LeftCol),
         Math.Max(rng1.BottomRow, rng2.BottomRow),
         Math.Max(rng1.RightCol, rng2.RightCol));
 }