Spread Windows Forms 13.0 Product Documentation
FarPoint.Win.Spread Assembly / FarPoint.Win.Spread Namespace / FpSpread Class / FilterBarDropDownSelectionChanging Event
Example


In This Topic
    FilterBarDropDownSelectionChanging Event
    In This Topic
    Occurs when the user selects a value from the drop-down list in the filter bar editor.
    Syntax
    'Declaration
     
    Public Event FilterBarDropDownSelectionChanging As FilterBarDropDownSelectionChangingEventHandler
    'Usage
     
    Dim instance As FpSpread
    Dim handler As FilterBarDropDownSelectionChangingEventHandler
     
    AddHandler instance.FilterBarDropDownSelectionChanging, handler
    public event FilterBarDropDownSelectionChangingEventHandler FilterBarDropDownSelectionChanging
    Event Data

    The event handler receives an argument of type FilterBarDropDownSelectionChangingEventArgs containing data related to this event. The following FilterBarDropDownSelectionChangingEventArgs properties provide information specific to this event.

    PropertyDescription
    The new value.  
    Specifies the column index.  
    Indicates whether the new value is handled.  
    Example
    This example uses the FilterBarDropDownSelectionChanging event.
    private void Form1_Load(object sender, EventArgs e)
            {
                System.Globalization.DateTimeFormatInfo dtf = new System.Globalization.DateTimeFormatInfo();
                dtf.LongDatePattern = "D";
                dtf.ShortDatePattern = "M/d/yyyy";
    
                FarPoint.Win.Spread.CellType.FilterBarCellType fbcell = new FarPoint.Win.Spread.CellType.FilterBarCellType();
                fbcell.AutoFormat = true;
                fbcell.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.DateTime;
                fbcell.DateTimeFormatInfo = dtf;
                fpSpread1.Sheets[0].AutoFilterMode = FarPoint.Win.Spread.AutoFilterMode.FilterBar;
                fpSpread1.Sheets[0].FilterBar.Cells[0].CellType = fbcell;
                fpSpread1.Sheets[0].Cells[0, 0].Value = DateTime.Now;
    }
    
            private void fpSpread1_FilterBarDropDownSelectionChanging(object sender, FarPoint.Win.Spread.CellType.FilterBarDropDownSelectionChangingEventArgs e)
            {
                if (e.ChangesObject is string) //all condition to Contains using wildcard
                {
                    // e.ChangesObject = "*" + e.ChangesObject.ToString() + "*";
                    //e.Handled = true; //notify to use new changed value
                }
                else if (e.ChangesObject is DateTime) //change DateTime to a short format string
                {
                    //e.ChangesObject = ((DateTime)e.ChangesObject).ToShortDateString();
                    FarPoint.Win.Spread.CellType.DateTimeCellType dc = new FarPoint.Win.Spread.CellType.DateTimeCellType();
                    dc.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined;
                    dc.UserDefinedFormat = "M/d/yy";
                    //e.ChangesObject = dc.Format(e.ChangesObject);
                    GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType datecell = new GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType();
                    GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayFieldInfo test = new GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayFieldInfo();
                    datecell.FocusPosition = GrapeCity.Win.Spread.InputMan.CellType.FieldsEditorFocusCursorPosition.MouseLocation;
                    datecell.Spin.AllowSpin = true;
                    datecell.Spin.IncrementValue = new TimeSpan(2);
                    datecell.DropDownCalendar.BackColor = Color.Red;
                    datecell.DropDownCalendar.CalendarDimensions = new Size(3, 1);
                    datecell.DropDownCalendar.Font = new Font("Arial", 10, FontStyle.Bold);              
                    datecell.DropDown.AllowDrop = true;
                    datecell.DropDown.AllowResize = true;
                    datecell.DropDown.AutoDropDown = true;
                    datecell.DefaultActiveField = datecell.Fields[2];
                    e.ChangesObject = datecell.Format(e.ChangesObject);
                    e.Handled = true; //notify to use new changed value
                }
                else if (e.ChangesObject is Color) // change color or icon enumerable
                {
                    if (((Color)e.ChangesObject) == Color.Red) e.ChangesObject = Color.DarkBlue;
                    e.Handled = true; //notify to use new changed value
                }
                else //by default it is false, not used
                    e.Handled = false; //notify to not use new changed value
            }
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim dtf As New System.Globalization.DateTimeFormatInfo
            dtf.LongDatePattern = "D"
            dtf.ShortDatePattern = "M/d/yyyy"
    
            Dim fbcell As New FarPoint.Win.Spread.CellType.FilterBarCellType()
            fbcell.AutoFormat = True
            fbcell.ContextMenuType = FarPoint.Win.Spread.CellType.FilterBarContextMenuType.DateTime
            fbcell.DateTimeFormatInfo = dtf
            FpSpread1.Sheets(0).AutoFilterMode = FarPoint.Win.Spread.AutoFilterMode.FilterBar
            FpSpread1.Sheets(0).FilterBar.Cells(0).CellType = fbcell
            FpSpread1.Sheets(0).Cells(0, 0).Value = DateTime.Now
    End Sub
    
     Private Sub FpSpread1_FilterBarDropDownSelectionChanging(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.CellType.FilterBarDropDownSelectionChangingEventArgs) Handles FpSpread1.FilterBarDropDownSelectionChanging
            If TypeOf e.ChangesObject Is String Then
                ' e.ChangesObject = "*" + e.ChangesObject.ToString() + "*";
                'e.Handled = true; //notify to use new changed value
                'all condition to Contains using wildcard
            ElseIf TypeOf e.ChangesObject Is DateTime Then
                'change DateTime to a short format string
                'e.ChangesObject = ((DateTime)e.ChangesObject).ToShortDateString();
                Dim dc As New FarPoint.Win.Spread.CellType.DateTimeCellType()
                dc.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined
                dc.UserDefinedFormat = "M/d/yy"
                'e.ChangesObject = dc.Format(e.ChangesObject);
                Dim datecell As New GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType()
                Dim test As New GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayFieldInfo()           
                datecell.FocusPosition = GrapeCity.Win.Spread.InputMan.CellType.FieldsEditorFocusCursorPosition.MouseLocation            
                datecell.Spin.AllowSpin = True
                datecell.Spin.IncrementValue = New TimeSpan(2)
                datecell.DropDownCalendar.BackColor = Color.Red
                datecell.DropDownCalendar.CalendarDimensions = New Size(3, 1)
                datecell.DropDownCalendar.Font = New Font("Arial", 10, FontStyle.Bold)
                'datecell.DropDownCalendar.HeaderStyle.BackColor = Color.Green;
                datecell.DropDown.AllowDrop = True
                datecell.DropDown.AllowResize = True
                datecell.DropDown.AutoDropDown = True
                datecell.DefaultActiveField = datecell.Fields(2)
                e.ChangesObject = datecell.Format(e.ChangesObject)
                'notify to use new changed value
                e.Handled = True
            ElseIf TypeOf e.ChangesObject Is Color Then
                ' change color or icon enumerable
                If DirectCast(e.ChangesObject, Color) = Color.Red Then
                    e.ChangesObject = Color.DarkBlue
                End If
                'notify to use new changed value
                e.Handled = True
            Else
                'by default it is false, not used
                e.Handled = False
            End If
            'notify to not use new changed value
        End Sub
    See Also