This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
/
Form1.cs
93 lines (84 loc) · 3.72 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;
namespace WindowsApplication53
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
PopulateTable();
pivotGridControl1.RefreshData();
pivotGridControl1.BestFit();
}
private void PopulateTable()
{
DataTable myTable = dataSet1.Tables["Data"];
myTable.Rows.Add(new object[] {"Aaa", DateTime.Today, 7});
myTable.Rows.Add(new object[] { "Aaa", DateTime.Today.AddDays(1), 4 });
myTable.Rows.Add(new object[] { "Bbb", DateTime.Today, 12 });
myTable.Rows.Add(new object[] { "Bbb", DateTime.Today.AddDays(1), 12 });
myTable.Rows.Add(new object[] { "Ccc", DateTime.Today, 11 });
myTable.Rows.Add(new object[] { "Ccc", DateTime.Today.AddDays(1), 9 });
myTable.Rows.Add(new object[] { "Aaa", DateTime.Today.AddYears(1), 4 });
myTable.Rows.Add(new object[] { "Aaa", DateTime.Today.AddYears(1).AddDays(1), 2 });
myTable.Rows.Add(new object[] { "Bbb", DateTime.Today.AddYears(1), 12 });
myTable.Rows.Add(new object[] { "Bbb", DateTime.Today.AddDays(1).AddYears(1), 1 });
myTable.Rows.Add(new object[] { "Ccc", DateTime.Today.AddYears(1), 9 });
myTable.Rows.Add(new object[] { "Ccc", DateTime.Today.AddDays(1).AddYears(1), 22 });
}
private void pivotGridControl1_CustomDrawCell(object sender, DevExpress.XtraPivotGrid.PivotCustomDrawCellEventArgs e)
{
int xl = FindLeftMostEqualCell(e);
int xr = FindRightMostEqualCell(e, ((PivotGridControl)sender).Cells.ColumnCount) ;
if (xl == e.ColumnIndex && xr > e.ColumnIndex)
{
int width = e.Bounds.Width;
int left = e.Bounds.Left - width * ( e.ColumnIndex - xl ) ;
int right = e.Bounds.Right + width * (xr - e.ColumnIndex) - 1;
Rectangle rec = new Rectangle(left, e.Bounds.Top , right - left, e.Bounds.Height -1 );
e.Graphics.FillRectangle(e.Appearance.GetBackBrush(e.GraphicsCache) , rec );
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(e.DisplayText, e.Appearance.Font , e.Appearance.GetForeBrush(e.GraphicsCache ), rec, sf);
e.Handled = true;
}
if (xl < e.ColumnIndex)
e.Handled = true;
}
private int FindRightMostEqualCell(DevExpress.XtraPivotGrid.PivotCustomDrawCellEventArgs e, int columnCount)
{
int x = e.ColumnIndex;
for (int i = e.ColumnIndex + 1 ; i < columnCount; i++)
{
if (e.GetCellValue(e.ColumnIndex, e.RowIndex).Equals(e.GetCellValue(i, e.RowIndex)))
x = i;
else
return x;
}
return x;
}
private int FindLeftMostEqualCell(DevExpress.XtraPivotGrid.PivotCustomDrawCellEventArgs e)
{
int x = e.ColumnIndex;
for (int i = e.ColumnIndex -1 ; i >= 0; i--)
{
if (e.GetCellValue(e.ColumnIndex, e.RowIndex).Equals(e.GetCellValue(i, e.RowIndex)))
x = i;
else
return x;
}
return x;
}
}
}