public GenericGridFilterControlWin(IGridBase grid)
{
var ds = grid.DataSource as DataView;
if (ds != null) this._originalView = ds;
(grid as DataGridView).DataSourceChanged += this.DataSourceChanged;
this._lastForcedEvents = DateTime.Now;
this.Grid = grid;
this._timer = new Timer()
{
Enabled = true,
Interval = 500,
};
this._timer.Tick += (sender, e) =>
{
if ((this._filterRequired) && (this._lastFilterChanged.AddMilliseconds(this._timer.Interval) < DateTime.Now))
{
if (this._inFilter)
this._cancelCurrentFilter = true;
this._filterRequired = false;
this.DoFilter();
}
};
var factory = new ControlFactoryWin();
this._filterLabel = factory.CreateLabel("Filter:");
this._filterTextBox = factory.CreateTextBox();
var txt = this._filterTextBox as TextBox;
txt.TextChanged += (sender, e) =>
{
if (txt.Text == this._lastFilterText) return;
this._lastFilterChanged = DateTime.Now;
this._filterRequired = true;
};
var manager = factory.CreateBorderLayoutManager(this);
manager.AddControl(this._filterLabel, BorderLayoutManager.Position.West);
manager.AddControl(this._filterTextBox, BorderLayoutManager.Position.Centre);
var vgap = manager.VerticalGapSize + manager.BorderSize;
this.Height = this._filterTextBox.Height + 2 * vgap;
this.FilterStarted += (sender, e) =>
{
this.SetUIState(true);
};
this.FilterCompleted += (sender, e) =>
{
this.SetUIState(false);
};
var wingrid = Grid as DataGridView;
if (wingrid != null)
{
this._gridOriginalAlternatingStyle = wingrid.AlternatingRowsDefaultCellStyle;
wingrid.AlternatingRowsDefaultCellStyleChanged += this.RecordGridAltStyle;
}
}