This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
Form1.cs
91 lines (83 loc) · 3.49 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
using DevExpress.Utils;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace GridCellsCreepingLine
{
public partial class Form1 : Form
{
private GridColumn column = null;
private bool creep = false;
private int rowHandle = -1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
gridControl1.DataSource = GetPersonDataTable();
gridControl1.GetToolTipController().GetActiveObjectInfo += new ToolTipControllerGetActiveObjectInfoEventHandler(OnGridControlToolTipControllerGetActiveObjectInfo);
}
DataTable GetPersonDataTable()
{
DataTable table = new DataTable();
table.TableName = "Persons";
table.Columns.Add(new DataColumn("FirstName", typeof(string)));
table.Columns.Add(new DataColumn("SecondName", typeof(string)));
table.Columns.Add(new DataColumn("Age", typeof(int)));
table.Columns.Add(new DataColumn("ID", typeof(int)));
for(int i = 0; i < 50; i++)
table.Rows.Add("Adam van Dorian " + i, "Peterson-Don-Abraham " + i, 20 + i / 2, i);
return table;
}
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if(creep && e.Column == column && e.RowHandle == rowHandle)
{
SizeF szCellValue = e.Appearance.CalcTextSize(e.Graphics, Convert.ToString(e.CellValue) + ".", 1000);
if(szCellValue.Width > e.Bounds.Width)
{
if(e.DisplayText == Convert.ToString(e.CellValue))
e.DisplayText = e.DisplayText + ' ';
char letter = e.DisplayText[0];
e.DisplayText = e.DisplayText.Remove(0, 1);
e.DisplayText = e.DisplayText + letter;
}
}
else { e.DisplayText = e.DisplayText; }
}
private void gridView1_MouseMove(object sender, MouseEventArgs e)
{
GridView view = sender as GridView;
GridHitInfo hitInfo = view.CalcHitInfo(e.X, e.Y);
if(hitInfo.HitTest == GridHitTest.RowCell)
{
if(column != hitInfo.Column || rowHandle != hitInfo.RowHandle)
{
int previousRowhandle = rowHandle;
GridColumn previousColumn = column;
column = hitInfo.Column;
rowHandle = hitInfo.RowHandle;
view.RefreshRowCell(previousRowhandle, previousColumn);
}
}
}
private void OnGridControlToolTipControllerGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
if(e.Info == null)
return;
GridHitInfo hitInfo = gridView1.CalcHitInfo(e.ControlMousePosition.X, e.ControlMousePosition.Y);
if(hitInfo.HitTest == GridHitTest.RowCell)
e.Info.Text = Convert.ToString(gridView1.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column));
}
private void timer1_Tick(object sender, EventArgs e)
{
creep = true;
gridView1.InvalidateRowCell(rowHandle, column);
}
}
}