This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyGridView.cs
78 lines (75 loc) · 3.37 KB
/
MyGridView.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
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Drawing;
using DevExpress.XtraEditors.Repository;
using DevExpress.Utils;
using DevExpress.XtraEditors.Container;
namespace MyXtraGrid
{
[System.ComponentModel.DesignerCategory("")]
public class MyGridView : DevExpress.XtraGrid.Views.Grid.GridView
{
public MyGridView() : this(null) { }
public MyGridView(DevExpress.XtraGrid.GridControl grid)
: base(grid)
{
OptionsView.AllowCellMerge = true;
}
protected override string ViewName { get { return "MyGridView"; } }
protected override void ActivateEditor(GridCellInfo cell)
{
if (cell.MergedCell == null)
base.ActivateEditor(cell);
else
ActivateMergedCellEditor(cell);
}
private void ActivateMergedCellEditor(GridCellInfo cell)
{
if (cell == null) return;
cell = cell.MergedCell.MergedCells[0];
this.fEditingCell = cell;
Rectangle bounds = GetMergedEditorBounds(cell);
if (bounds.IsEmpty) return;
RepositoryItem cellEdit = RequestCellEditor(cell);
ViewInfo.UpdateCellAppearance(cell);
ViewInfo.RequestCellEditViewInfo(cell);
AppearanceObject appearance = new AppearanceObject();
AppearanceHelper.Combine(appearance, new AppearanceObject[] { GetEditorAppearance(), ViewInfo.PaintAppearance.Row, cell.Appearance });
if (cellEdit != cell.Editor && cellEdit.DefaultAlignment != HorzAlignment.Default)
{
appearance.TextOptions.HAlignment = cellEdit.DefaultAlignment;
}
UpdateEditor(cellEdit, new UpdateEditorInfoArgs(GetColumnReadOnly(cell.ColumnInfo.Column), bounds, appearance, cell.CellValue, ElementsLookAndFeel, cell.ViewInfo.ErrorIconText, cell.ViewInfo.ErrorIcon));
ViewInfo.UpdateCellAppearance(cell);
if (cell != null)
InvalidateRow(cell.RowHandle);
}
Rectangle GetMergedEditorBounds(GridCellInfo cell)
{
Rectangle r = cell.CellValueRect;
Rectangle bounds = ViewInfo.UpdateFixedRange(r, cell.ColumnInfo);
if (bounds.Right > ViewInfo.ViewRects.Rows.Right)
{
bounds.Width = ViewInfo.ViewRects.Rows.Right - bounds.Left;
}
if (bounds.Bottom > ViewInfo.ViewRects.Rows.Bottom)
{
bounds.Height = ViewInfo.ViewRects.Rows.Bottom - bounds.Top;
}
if (bounds.Width < 1 || bounds.Height < 1) return Rectangle.Empty; ;
for (int i = 1; i < cell.MergedCell.MergedCells.Count; i++)
bounds.Height += cell.MergedCell.MergedCells[i].Bounds.Height;
return bounds;
}
protected override bool PostEditor(bool causeValidation)
{
if (IsEditing)
if (this.fEditingCell.MergedCell != null)
{
object CurValue = ExtractEditingValue(this.fEditingCell.ColumnInfo.Column, EditingValue);
for (int i = 0; i < fEditingCell.MergedCell.MergedCells.Count; i++)
this.SetRowCellValue(this.fEditingCell.RowHandle + i, this.fEditingCell.Column, CurValue);
}
return base.PostEditor(causeValidation);
}
}
}