/// <summary> /// TODO: Documentation ApplyFilter /// </summary> /// <param name="filterResult"></param> /// <param name="filterText"></param> /// <returns></returns> private FilterResult ApplyFilter(FilterResult filterResult, String filterText, Int32 index) { if (index < this.MaxCaptionItems) { filterResult.Caption += "\n"; } if (ColumnDataType == typeof(String)) { // Managing the string-column case String escapedFilterValue = DgvBaseColumnFilter.StringEscape(filterText.ToString()); filterResult.Expression = String.Format(CultureInfo.CurrentCulture, "{0}'{1}',", filterResult.Expression, escapedFilterValue); if (index < this.MaxCaptionItems) { filterResult.Caption = String.Format(CultureInfo.CurrentCulture, "{0}= {1}", filterResult.Caption, filterText); } } else { // Managing the other cases String formattedValue = DgvBaseColumnFilter.FormatValue(filterText, this.ColumnDataType); if (!String.IsNullOrEmpty(formattedValue)) { filterResult.Expression = String.Format(CultureInfo.CurrentCulture, "{0}{1},", filterResult.Expression, formattedValue); if (index < this.MaxCaptionItems) { filterResult.Caption = String.Format(CultureInfo.CurrentCulture, "{0}= {1}", filterResult.Caption, filterText); } } } return(filterResult); }
/// <summary> /// Initializes a new instance of the <see cref="ColumnFilterEventArgs"/> class. /// </summary> /// <param name="Column">The DstaGridView column.</param> /// <param name="ColumnFilter">The column filter instance.</param> public ColumnFilterEventArgs(DataGridViewColumn Column, DgvBaseColumnFilter ColumnFilter) { mColumn = Column; mColumnFilter = ColumnFilter; mHandled = Handled; }
/// <summary> /// Builds the filter expression and raises the FilterExpressionBuilding event /// </summary> /// <param name="sender">The event source.</param> /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> userPermissions containing the event data.</param> /// <remarks> /// Override <b>OnFilterExpressionBuilding</b> to provide a filter expression construction /// logic and to set the values of the <see cref="DgvBaseColumnFilter.FilterExpression"/> and <see cref="DgvBaseColumnFilter.FilterCaption"/> properties. /// The <see cref="DgvFilterManager"/> will use these properties in constructing the whole filter expression and to change the header text of the filtered column. /// Otherwise, you can create an event handler and set the <i>Cancel</i> ctl of event argument to true, to skip standard filter expression building logic. /// </remarks> protected override void OnFilterExpressionBuilding(object sender, CancelEventArgs e) { base.OnFilterExpressionBuilding(sender, e); if (e.Cancel) { this.FilterManager.RebuildFilter(); return; } String resultFilterCaption = this.OriginalDataGridViewColumnHeaderText + "\n"; String resultFilterExpression = String.Empty; // Managing the NULL and NOT NULL cases which are entityType-independent if (this.comboBoxOperator.Text == "= Ø") { resultFilterExpression = DgvBaseColumnFilter.GetNullCondition(this.DataGridViewColumn.DataPropertyName); } if (this.comboBoxOperator.Text == "<> Ø") { resultFilterExpression = DgvBaseColumnFilter.GetNotNullCondition(this.DataGridViewColumn.DataPropertyName); } if (!String.IsNullOrEmpty(resultFilterExpression)) { this.FilterExpression = resultFilterExpression; this.FilterCaption = resultFilterCaption + "\n" + this.comboBoxOperator.Text; this.FilterManager.RebuildFilter(); return; } FilterResult filterResult = new FilterResult(); filterResult = this.ApplyFilter(filterResult, this.comboBoxOperator, this.textBoxValue.Text, null); foreach (FilterComponents filter in this._filters) { if (!String.IsNullOrEmpty(filter.TextBoxValue.Text)) { filterResult = this.ApplyFilter(filterResult, filter.ComboBoxOperator, filter.TextBoxValue.Text, filter.ComboBoxAndOr.Text); } } resultFilterExpression = filterResult.Expression; resultFilterCaption += filterResult.Caption; if (!String.IsNullOrEmpty(resultFilterExpression)) { this.FilterExpression = resultFilterExpression; this.FilterCaption = resultFilterCaption; this.FilterManager.RebuildFilter(); } }