-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridFixedColumnModule.cs
More file actions
98 lines (93 loc) · 4.87 KB
/
GridFixedColumnModule.cs
File metadata and controls
98 lines (93 loc) · 4.87 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.Utils.Svg;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
namespace WindowsFormsAppCustomProperties {
public class GridFixedColumnModule {
public static readonly string PropertyName = "FixedColumns";
readonly DashboardDesigner designer;
public GridFixedColumnModule(DashboardDesigner designer, SvgImage barImage = null) {
this.designer = designer;
RibbonControl ribbon = (RibbonControl)designer.MenuManager;
RibbonPage page = ribbon.GetDashboardRibbonPage(DashboardBarItemCategory.GridTools, DashboardRibbonPage.Design);
RibbonPageGroup group = page.GetGroupByName("Custom Properties");
if(group == null) {
group = new RibbonPageGroup("Custom Properties") { Name = "Custom Properties" };
page.Groups.Add(group);
}
BarButtonItem barItem = CreateBarItem("Fix Columns", barImage);
group.ItemLinks.Add(barItem);
barItem.ItemClick += ChangeCustomPropertyValue;
designer.DashboardItemControlUpdated += Designer_DashboardItemControlUpdated;
}
BarButtonItem CreateBarItem(string caption, SvgImage barImage) {
BarButtonItem barItem = new BarButtonItem();
barItem.Caption = caption;
barItem.ImageOptions.SvgImage = barImage;
return barItem;
}
void Designer_DashboardItemControlUpdated(object sender, DashboardItemControlEventArgs e) {
if(e.GridControl != null) {
GridDashboardItem gridItem = designer.Dashboard.Items[e.DashboardItemName] as GridDashboardItem;
gridItem.GridOptions.ColumnWidthMode = GridColumnWidthMode.AutoFitToContents;
foreach(GridColumnBase itemColumn in gridItem.Columns) {
string customProperty = itemColumn.CustomProperties.GetValue(PropertyName);
if(!string.IsNullOrEmpty(customProperty)) {
GridColumn gridColumn = e.GridContext.GetControlColumn(itemColumn);
if(gridColumn != null) {
bool fixedWidthEnabled = Convert.ToBoolean(itemColumn.CustomProperties.GetValue(PropertyName));
gridColumn.Fixed = fixedWidthEnabled ? FixedStyle.Left : FixedStyle.None;
}
}
}
}
}
void ChangeCustomPropertyValue(object sender, ItemClickEventArgs e) {
GridDashboardItem gridItem = designer.SelectedDashboardItem as GridDashboardItem;
List<CheckedComboBoxItem> checkedColumnsList = gridItem.Columns.Select(x => new CheckedComboBoxItem() {
Column = x,
Checked = Convert.ToBoolean(x.CustomProperties.GetValue(PropertyName))
}).ToList();
ColumnSelectorControl control = new ColumnSelectorControl(checkedColumnsList);
if(XtraDialog.Show(control, "Select columns to fix:") == DialogResult.OK) {
foreach(var item in checkedColumnsList)
if(Convert.ToBoolean(item.Column.CustomProperties.GetValue(PropertyName)) != item.Checked) {
string status = item.Checked == true ? "Pin" : "Unpin";
CustomPropertyHistoryItem historyItem = new CustomPropertyHistoryItem(item.Column, PropertyName, item.Checked.ToString(), $"{status} the {item} column");
designer.AddToHistory(historyItem);
}
}
}
}
public class CheckedComboBoxItem {
public GridColumnBase Column { get; set; }
public bool Checked { get; set; }
public override string ToString() {
return Column.GetDisplayName();
}
}
public class ColumnSelectorControl: XtraUserControl {
CheckedListBoxControl checkedCombo = new CheckedListBoxControl();
public ColumnSelectorControl(List<CheckedComboBoxItem> gridColumns) {
foreach(CheckedComboBoxItem col in gridColumns) {
checkedCombo.Items.Add(col, col.Checked);
}
checkedCombo.ItemCheck += CheckedCombo_ItemCheck;
checkedCombo.Dock = DockStyle.Fill;
Controls.Add(checkedCombo);
Dock = DockStyle.Top;
}
void CheckedCombo_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) {
CheckedListBoxControl checkList = sender as CheckedListBoxControl;
CheckedComboBoxItem item = checkList.Items[e.Index].Value as CheckedComboBoxItem;
item.Checked = checkList.Items[e.Index].CheckState == CheckState.Checked;
}
}
}