Ejemplo n.º 1
0
        void pivotGridControl_CellDoubleClick(object sender, DevExpress.XtraPivotGrid.PivotCellEventArgs e)
        {
            // TODO: move to Win Forms
            int columnIndex = e.ColumnIndex;
            int rowIndex    = e.RowIndex;

            // add custom columns
            var columns = new List <string>();

            foreach (PivotGridFieldBase field in pivotGridControl1.Fields)
            {
                columns.Add(field.FieldName);
            }

            // print selected fields

            foreach (PivotGridField field in pivotGridControl1.Fields)
            {
                // print Field Name and Value
                // TODO: ignore fields if there is a field in a lower hierarchy
                var pivotValue = e.GetFieldValue(field);
                if (pivotValue != null)
                {
                    Debug.Print(string.Format("{0} = {1}", field.FieldName, pivotValue));
                }
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable tbl = new DataTable();

            if (pivotGridControl1.Cells.RowCount == 0)
            {
                return;
            }

            List <PivotGridField> rowFields = pivotGridControl1.GetFieldsByArea(PivotArea.RowArea);

            foreach (PivotGridField rowField in rowFields)
            {
                tbl.Columns.Add(rowField.ToString());
            }
            for (int i = 0; i < pivotGridControl1.Cells.ColumnCount; i++)
            {
                tbl.Columns.Add(GetColumnFieldValueText(pivotGridControl1, pivotGridControl1.Cells.GetCellInfo(i, 0)));
            }



            for (int rowIndex = 0; rowIndex < pivotGridControl1.Cells.RowCount; rowIndex++)
            {
                DataRow row = tbl.NewRow();
                DevExpress.XtraPivotGrid.PivotCellEventArgs cellInfo = pivotGridControl1.Cells.GetCellInfo(0, rowIndex);

                foreach (PivotGridField rowField in rowFields)
                {
                    row[rowField.AreaIndex] = cellInfo.GetFieldValue(rowField);
                }

                for (int columnIndex = 0; columnIndex < pivotGridControl1.Cells.ColumnCount; columnIndex++)
                {
                    row[columnIndex + rowFields.Count] = pivotGridControl1.Cells.GetCellInfo(columnIndex, rowIndex).Value;
                }
                tbl.Rows.Add(row);
            }
            dataGridView1.DataSource = tbl;
        }