/
GridViewSearch.cs
85 lines (73 loc) · 2.33 KB
/
GridViewSearch.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
namespace WindowsApplication1
{
public partial class GridViewSearch : UserControl
{
public GridViewSearch()
{
InitializeComponent();
}
private GridColumn _SearchColumn;
public GridColumn SearchColumn
{
get { return _SearchColumn; }
set { _SearchColumn = value; }
}
private string _SearchText;
public string SearchText
{
get { return _SearchText; }
set { _SearchText = value; OnSearchTextChanged(); }
}
private void OnSearchTextChanged()
{
btSearch.Text = _SearchText;
}
GridView GetSearchGridView()
{
return SearchColumn.View as GridView;
}
int FindRow(int startRowHandle, bool isForward)
{
if (SearchColumn == null) return GridControl.InvalidRowHandle;
startRowHandle = Math.Max(0, startRowHandle);
GridView view = GetSearchGridView();
try
{
int delta = isForward ? 1 : -1;
int n = startRowHandle;
while (view.IsValidRowHandle(n))
{
n += delta;
string cellText = GetSearchGridView().GetRowCellDisplayText(n, SearchColumn);
if (cellText.Contains(SearchText)) return n;
}
}
catch { }
return GridControl.InvalidRowHandle;
}
private void FocusNextRow(bool isForward)
{
GridView searchGridView = GetSearchGridView();
int focusedRowHandle = FindRow(searchGridView.FocusedRowHandle, isForward);
searchGridView.FocusedRowHandle = focusedRowHandle;
}
private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
FocusNextRow(!e.Button.IsLeft);
}
private void btSearchChanged(object sender, EventArgs e)
{
SearchText = btSearch.Text;
}
}
}