/// <summary> /// This routine is called when the user has changed /// the FilterPanel edit value (TextBox, ComboBox, or CheckBox). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void SuperGridControl1FilterEditValueChanged( object sender, GridFilterEditValueChangedEventArgs e) { if (e.GridColumn.Name.Equals("Age")) { AgeEditValueChanged(e); } else if (e.GridColumn.Name.Equals("LastName")) { LastNameEditValueChanged(e); } }
/// <summary> /// This routine handles "Age" related edit changes. /// </summary> /// <param name="e"></param> private void AgeEditValueChanged(GridFilterEditValueChangedEventArgs e) { string s = e.NewValue as string; if (s != null) { // Let's permit the user to type in things like // "20-25,27,31-40" as a valid edit filter. Regex reg = new Regex("((?<age>\\d+(?!-)\\b)|(?<range>\\d+-\\d+))\\s*,*\\s*"); MatchCollection mc = reg.Matches(s); if (mc.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (Match ma in mc) { Group gp = ma.Groups["age"]; sb.Append(e.GridColumn.Name); if (gp != null && string.IsNullOrEmpty(gp.Value) == false) { sb.Append(" is like \"" + gp.Value + "\" or "); } gp = ma.Groups["range"]; if (gp != null && string.IsNullOrEmpty(gp.Value) == false) { string[] t = gp.Value.Split('-'); sb.Append(" is between " + t[0] + " and " + t[1] + " or "); } } sb.Length -= 4; // Override the default parsed SuperGrid Filter Expression // with our new range enabled expression. e.NewExpr = sb.ToString(); e.NewDisplayValue = s; } } }
/// <summary> /// This routine handles "LastName" related edit changes. /// </summary> /// <param name="e"></param> private void LastNameEditValueChanged(GridFilterEditValueChangedEventArgs e) { ComboBoxEx cb = e.FilterPanel.Control as ComboBoxEx; if (cb != null) { // We only want to handle selections for our // items, so make sure it is one of our items. MyItem item = cb.SelectedItem as MyItem; if (item != null) { string s = ((string)e.NewValue).Replace("to", "and"); e.NewExpr = "LastName between " + s; } } }