Esempio n. 1
0
        private void PopulateDataGrid()
        {
            // define the data source
            List <BigTableRow> dg_rows = new List <BigTableRow>();

            if (this.DataField.RowNames == null || this.DataField.RowNames.Count == 0)
            {
                for (int i = 0; i < this.DataField.Values.Count; i++)
                {
                    BigTableRow dg_row = new BigTableRow(i + 1, this.DataField.Values[i]);
                    dg_rows.Add(dg_row);
                }
            }
            else
            {
                for (int i = 0; i < this.DataField.Values.Count; i++)
                {
                    BigTableRow dg_row = new BigTableRow(i + 1, this.DataField.RowNames[i], this.DataField.Values[i]);
                    dg_rows.Add(dg_row);
                }
            }
            this.ItemsSource = dg_rows;

            // define the headers
            DataGridTextColumn col_nr = new DataGridTextColumn();

            col_nr.Header     = "Nr";
            col_nr.Binding    = new Binding("Col00");
            col_nr.FontWeight = FontWeights.Bold;
            col_nr.CellStyle  = (Style)this.TryFindResource("BigTable_DataGridCell");
            this.Columns.Add(col_nr);
            if (this.DataField.RowNames == null)
            {
                for (int i = 0; i < this.DataField.Names.Count; i++)
                {
                    DataGridTextColumn col_i = new DataGridTextColumn();
                    col_i.Header  = this.DataField.Names[i] + "\n" + this.DataField.Units[i];
                    col_i.Binding = new Binding("Col" + (i + 1).ToString("D2"));
                    this.Columns.Add(col_i);
                }
            }
            else
            {
                for (int i = 1; i < this.DataField.Names.Count; i++)
                {
                    DataGridTextColumn col_i = new DataGridTextColumn();
                    col_i.Header  = this.DataField.Names[i] + "\n" + this.DataField.Units[i];
                    col_i.Binding = new Binding("Col" + (i).ToString("D2"));
                    this.Columns.Add(col_i);
                }
            }

            // define the selection (in the Loaded event handler)

            // define the event handlers
            this.SelectedCellsChanged += table_SelectedCellsChanged;
        }
Esempio n. 2
0
        private void table_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            DataGrid dg = sender as DataGrid;

            if (dg == null || e == null)
            {
                return;
            }

            if (e.AddedCells != null && e.AddedCells.Count > 0)
            {
                BigTableRow item = e.AddedCells[0].Item as BigTableRow;
                if (item != null)
                {
                    int row_ind = item.Col00_Index - 1;

                    int col_ind = e.AddedCells[0].Column.DisplayIndex;

                    string content = item.GetColAt(col_ind);
                    double value   = 0;
                    bool   success = double.TryParse(content, NumberStyles.Float, BigTableRow.FORMATTER, out value);
                    if (success)
                    {
                        RectangularValue rv = new RectangularValue()
                        {
                            RightBottom = value,
                            RightTop    = value,
                            LeftBottom  = value,
                            LeftTop     = value
                        };
                        MultiValPointer pointer = new MultiValPointer(new List <int> {
                            row_ind, col_ind, 0
                        }, new Point(1, 1), new Point(0, 0), true, rv, false);
                        if (pointer != MultiValPointer.INVALID)
                        {
                            this.DataField.MVDisplayVector = pointer;
                        }
                    }
                }
            }
        }