This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
MyVGridControl.cs
104 lines (96 loc) · 4.12 KB
/
MyVGridControl.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
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.XtraVerticalGrid;
using System.ComponentModel;
using DevExpress.XtraEditors;
using System.Drawing;
using DevExpress.XtraVerticalGrid.Internal;
namespace XtraVerticalGridNavigation {
internal class MyVGridControl : VGridControl {
private bool useEmbeddedNavigator;
[Browsable(true),
DefaultValue(false),
Description("Gets or sets whether the embedded data navigator is visible.")]
public bool UseEmbeddedNavigator {
get {
return useEmbeddedNavigator;
}
set {
EmbeddedNavigator.Visible = value;
useEmbeddedNavigator = value;
((MyVGridScroller)Scroller).Invalidate();
}
}
private ControlNavigator embeddedNavigator = new ControlNavigator();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ControlNavigator EmbeddedNavigator {
get {
return embeddedNavigator;
}
set {
embeddedNavigator = value;
}
}
public MyVGridControl()
: base() {
EmbeddedNavigator.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
EmbeddedNavigator.TextLocation = NavigatorButtonsTextLocation.Center;
EmbeddedNavigator.NavigatableControl = this;
EmbeddedNavigator.Left = 1;
Controls.Add(EmbeddedNavigator);
EmbeddedNavigator.Hide();
}
protected override VGridScroller CreateScroller() {
return new MyVGridScroller(this);
}
public class MyVGridScroller : VGridScroller {
private MyVGridControl mygrid;
public MyVGridScroller(VGridControlBase grid)
: base(grid) {
mygrid = (MyVGridControl)grid;
}
internal Rectangle ScrollSquare {
get {
return new Rectangle(mygrid.ClientRectangle.Right - ScrollInfo.VScrollWidth, mygrid.ClientRectangle.Bottom - ScrollInfo.HScrollHeight, ScrollInfo.VScrollWidth, ScrollInfo.HScrollHeight);
}
}
private Rectangle ScrollRect() {
if (mygrid.UseEmbeddedNavigator) {
return GetScrollRectWithNavigator();
} else {
return GetScrollRectWithoutNavigator();
}
}
private Rectangle GetScrollRectWithNavigator() {
return new Rectangle(1 + mygrid.EmbeddedNavigator.Width, 1, mygrid.Bounds.Width - 2 - mygrid.EmbeddedNavigator.Width + 15 - ScrollInfo.VScrollWidth, mygrid.Bounds.Height - ScrollInfo.HScrollHeight);
}
private Rectangle GetScrollRectWithoutNavigator() {
return new Rectangle(mygrid.Bounds.Left + 1, mygrid.Bounds.Top + 1, mygrid.Bounds.Width - 2, mygrid.Bounds.Height - 20);
}
public void Invalidate() {
Update();
}
public override void Update() {
try {
UpdateHScrollBar();
UpdateVScrollBar();
ScrollInfo.UpdateScrollerLocation(ScrollRect());
mygrid.ViewInfo.ViewRects.ScrollSquare = ScrollSquare;
if (mygrid.UseEmbeddedNavigator) {
mygrid.EmbeddedNavigator.Height = ScrollInfo.HScrollHeight - 1;
mygrid.EmbeddedNavigator.Top = mygrid.Bounds.Height - mygrid.EmbeddedNavigator.Height - 1;
}
var leftRecord = LeftVisibleRecord;
var topRowIndex = TopVisibleRowIndex;
LeftVisibleRecord = leftRecord;
TopVisibleRowIndex = topRowIndex;
if (leftRecord != LeftVisibleRecord || topRowIndex != TopVisibleRowIndex) {
mygrid.LayoutChanged();
}
} finally {
}
}
}
}
}