/// <summary> /// This extension is a free form method for filtering. The usage would be /// to provide a user interface to put together the condition. See unit /// test FreeForm_CaseSensitive_OnBoth_Conditions_LastField_NotExact /// </summary> /// <param name="sender">BindingSource with a DataTable set for the DataSource</param> /// <param name="pFilter">Filter condition</param> /// <param name="pCaseSensitive">True for case sensitive, false for case insensitive</param> public static void RowFilterFreeForm(this BindingSource sender, string pFilter, bool pCaseSensitive = false) { sender.DataTable().CaseSensitive = pCaseSensitive; sender.DataView().RowFilter = pFilter; }
/// <summary> /// Clear DataView RowFilter /// </summary> /// <param name="sender">BindingSource with a DataTable set for the DataSource</param> public static void RowFilterClear(this BindingSource sender) { sender.DataView().RowFilter = ""; }
/// <summary> /// Apply a filter for ends with /// </summary> /// <param name="sender">BindingSource with a DataTable set for the DataSource</param> /// <param name="pField">Field to apply filter on</param> /// <param name="pValue">Value for filter</param> /// <param name="pCaseSensitive">True for case sensitive, false for case insensitive</param> public static void RowFilterEndsWith(this BindingSource sender, string pField, string pValue, bool pCaseSensitive = false) { sender.DataTable().CaseSensitive = pCaseSensitive; sender.DataView().RowFilter = $"{pField} LIKE '%{pValue}'"; }
/// <summary> /// Apply filter to the DefaultView of the DataTable /// </summary> /// <param name="sender">BindingSource with a DataTable set for the DataSource</param> /// <param name="pField">Field to apply filter on</param> /// <param name="pValue">Value for filter</param> /// <param name="pCaseSensitive">Filter should be case or case in-sensitive</param> /// <returns>Filter has rows</returns> public static bool RowFilter(this BindingSource sender, string pField, string pValue, bool pCaseSensitive = false) { sender.DataTable().CaseSensitive = pCaseSensitive; sender.DataView().RowFilter = $"{pField} = '{pValue}'"; return(sender.Count > 0); }
/// <summary> /// Apply a filter for Like containts /// </summary> /// <param name="pSender"></param> /// <param name="pField">Field to apply filter on</param> /// <param name="pValue">Value for filter</param> /// <param name="pCaseSensitive">Filter should be case or case in-sensitive</param> public static void RowFilterContains(this BindingSource pSender, string pField, string pValue, bool pCaseSensitive = false) { pSender.DataTable().CaseSensitive = pCaseSensitive; pSender.DataView().RowFilter = $"{pField} LIKE '%{pValue.EscapeApostrophe()}%'"; }
public static void RowFilterTwoConditions(this BindingSource pSender, string pField1, string pValue1, string pField2, string pValue2, bool pCaseSensitive = false) { pSender.DataTable().CaseSensitive = pCaseSensitive; pSender.DataView().RowFilter = $"{pField1} = '{pValue1.EscapeApostrophe()}' AND {pField2} = '{pValue2.EscapeApostrophe()}'"; }
/// <summary> /// Apply a filter for Like starts with /// </summary> /// <param name="sender"></param> /// <param name="field">Field to apply filter on</param> /// <param name="value">Value for filter</param> /// <param name="caseSensitive">Filter should be case or case in-sensitive</param> public static void RowFilterStartsWith(this BindingSource sender, string field, string value, bool caseSensitive = false) { sender.DataTable().CaseSensitive = caseSensitive; sender.DataView().RowFilter = $"{field} LIKE '{value.EscapeApostrophe()}%'"; }