-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
73 lines (67 loc) · 2.65 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.Utils;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Random r = new Random();
public int GetRandomValue()
{
return r.Next(100) + 50;
}
private DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("UseStyles", typeof(bool));
tbl.Columns.Add("R", typeof(int));
tbl.Columns.Add("G", typeof(int));
tbl.Columns.Add("B", typeof(int));
for (int i = 0; i < RowCount; i++)
tbl.Rows.Add(new object[] { String.Format("Name{0}", i), false, GetRandomValue(), GetRandomValue(), GetRandomValue() });
return tbl;
}
public Form1()
{
AppearanceObject.DefaultFont = new Font(AppearanceObject.DefaultFont.FontFamily, 14, FontStyle.Bold);
InitializeComponent();
gridControl1.DataSource = CreateTable(5);
RepositoryItemCheckEdit riCheckEdit = new RepositoryItemCheckEdit();
gridView1.Columns["UseStyles"].ColumnEdit = riCheckEdit;
RepositoryItemTrackBar riTrackBar = new RepositoryItemTrackBar();
riTrackBar.Maximum = 255;
gridView1.Columns["R"].ColumnEdit = riTrackBar;
gridView1.Columns["G"].ColumnEdit = riTrackBar;
gridView1.Columns["B"].ColumnEdit = riTrackBar;
riCheckEdit.EditValueChanged += OnEditValueChanged;
riTrackBar.EditValueChanged += OnEditValueChanged;
gridView1.RowCellStyle += new RowCellStyleEventHandler(gridView1_RowCellStyle);
}
void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
if (!true.Equals(gridView1.GetRowCellValue(e.RowHandle, "UseStyles")))
return;
e.Appearance.BackColor = GetRowBackColor(e.RowHandle);
}
void OnEditValueChanged(object sender, EventArgs e)
{
gridView1.PostEditor();
}
private Color GetRowBackColor(int rowHandle)
{
return Color.FromArgb(GetColorValue(rowHandle, "R"), GetColorValue(rowHandle, "G"), GetColorValue(rowHandle, "B"));
}
private int GetColorValue(int rowHandle, string fieldName)
{
return (int)gridView1.GetRowCellValue(rowHandle, fieldName);
}
}
}