-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
58 lines (55 loc) · 2.18 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
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Q183147
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Random rand = new Random();
var list = new BindingList<Item>();
for (int i = 0; i < 50; i++)
list.Add(new Item() { ID = i, Name = "Name" + i, Category = rand.Next(0, 5) });
gridControl1.DataSource = list;
}
private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
int focusedRowHandle = -1;
if (e.FocusedRowHandle == GridControl.NewItemRowHandle || e.FocusedRowHandle == GridControl.AutoFilterRowHandle)
return;
GridView view = (GridView)sender;
if (e.FocusedRowHandle < 0)
{
if (e.PrevFocusedRowHandle == GridControl.InvalidRowHandle)
focusedRowHandle = 0;
else if (Control.MouseButtons == MouseButtons.Left || Control.MouseButtons == MouseButtons.Right)
focusedRowHandle = e.PrevFocusedRowHandle;
else
{
int prevRow = view.GetVisibleIndex(e.PrevFocusedRowHandle);
int currRow = view.GetVisibleIndex(e.FocusedRowHandle);
if (prevRow > currRow)
focusedRowHandle = e.PrevFocusedRowHandle - 1;
else
focusedRowHandle = e.PrevFocusedRowHandle + 1;
if (focusedRowHandle < 0) focusedRowHandle = 0;
if (focusedRowHandle >= view.DataRowCount) focusedRowHandle = view.DataRowCount - 1;
}
view.FocusedRowHandle = focusedRowHandle < 0 ? 0 : focusedRowHandle;
}
}
public class Item
{
public int ID { get; set; }
public string Name { get; set; }
public int Category { get; set; }
}
}
}