GrapeCity MultiRow Windows Forms Documentation
DropDownItemNeeded Event
Example 


Occurs when a DropDownItem is needed.
Syntax
Public Event DropDownItemNeeded As EventHandler(Of DropDownItemNeededEventArgs)
Dim instance As DropDownAutoFilterItem
Dim handler As EventHandler(Of DropDownItemNeededEventArgs)
 
AddHandler instance.DropDownItemNeeded, handler
public event EventHandler<DropDownItemNeededEventArgs> DropDownItemNeeded
Event Data

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

PropertyDescription
DropDownCustomFilterItemGets or sets the custom DropDownCustomFilterItem.  
FilterValueGets the filter value.  
Handled (Inherited from System.ComponentModel.HandledEventArgs)
Remarks
The event is used to customize the DropDownCustomFilterItem for each filter value. It allows you to create filter items with the specified text and image.
Example
The following code example shows how to use this event to customize the automatic filter items. This code example is part of a larger example provided for the DropDownList property.
void setThirdColumnDropDownListButton_Click(object sender, EventArgs e)
        {
            // Create a header drop down list without default down down items.
            HeaderDropDownList headerDropDownList = new HeaderDropDownList();

            DropDownItemCollection dropDownItemCollection = headerDropDownList.Items;

            // Initialize drop down items manually.
            // Add to show all items.
            dropDownItemCollection.Add(new DropDownShowAllFilterItem());

            DropDownAutoFilterItem autoFilterItem = new DropDownAutoFilterItem();

            autoFilterItem.DropDownItemNeeded += new 
EventHandler<DropDownItemNeededEventArgs>(autoFilterItem_DropDownItemNeeded);

            // custom range item.
            dropDownItemCollection.Add(autoFilterItem);

            // Get second column header cell.
            ColumnHeaderCell columnHeaderCell = this.gcMultiRow1.ColumnHeaders[0][2] as ColumnHeaderCell;
            columnHeaderCell.DropDownList = headerDropDownList;
        }

        void autoFilterItem_DropDownItemNeeded(object sender, DropDownItemNeededEventArgs e)
        {
            int filterValue = int.Parse(e.FilterValue.ToString());

            e.DropDownCustomFilterItem = new AutoRangeFilterItem(filterValue / 100);

            e.Handled = true;
        }

        public class AutoRangeFilterItem : DropDownCustomFilterItem
        {
            public AutoRangeFilterItem(int filterValue)
                : base(filterValue)
            {

            }

            public override string Text
            {
                get
                {
                    return ((int)FilterValue * 100).ToString() + " to " + (((int)FilterValue + 1) * 100).ToString();
                }
                set { }
            }

            protected override bool Check(object value)
            {
                // check whether the value is in specific range.
                int checkedValue = int.Parse(value.ToString());

                return (checkedValue >= ((int)FilterValue * 100) && checkedValue <= (((int)FilterValue + 1) * 100));
            }
        }
Private Sub setThirdColumnDropDownListButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles 
setThirdColumnDropDownListButton.Click
        ' Create a header drop down list without default down down items.
        Dim headerDropDownList As New HeaderDropDownList()

        Dim dropDownItemCollection As DropDownItemCollection = headerDropDownList.Items

        ' Initialize drop down items manually.
        ' Add to show all items.
        dropDownItemCollection.Add(New DropDownShowAllFilterItem())

        Dim autoFilterItem As New DropDownAutoFilterItem()

        AddHandler autoFilterItem.DropDownItemNeeded, AddressOf autoFilterItem_DropDownItemNeeded

        ' custom range item.
        dropDownItemCollection.Add(autoFilterItem)

        ' Get second column header cell.
        Dim columnHeaderCell As ColumnHeaderCell = TryCast(Me.gcMultiRow1.ColumnHeaders(0)(2), 
ColumnHeaderCell)
        columnHeaderCell.DropDownList = headerDropDownList
    End Sub

    Private Sub autoFilterItem_DropDownItemNeeded(ByVal sender As Object, ByVal e As 
DropDownItemNeededEventArgs)
        Dim filterValue As Integer = Integer.Parse(e.FilterValue.ToString())

        e.DropDownCustomFilterItem = New AutoRangeFilterItem(filterValue / 100)

        e.Handled = True
    End Sub

    Public Class AutoRangeFilterItem
        Inherits DropDownCustomFilterItem
        Public Sub New(ByVal filterValue As Integer)

            MyBase.New(filterValue)
        End Sub

        Public Overloads Overrides Property Text() As String
            Get
                Return (DirectCast(FilterValue, Integer) * 100).ToString() + " to " + ((DirectCast(FilterValue, Integer) + 1) * 
100).ToString()
            End Get
            Set(ByVal value As String)
            End Set
        End Property

        Protected Overloads Overrides Function Check(ByVal value As Object) As Boolean
            ' check the value whether in specific range.
            Dim checkedValue As Integer = Integer.Parse(value.ToString())

            Return (checkedValue >= (DirectCast(FilterValue, Integer) * 100) AndAlso checkedValue <= 
((DirectCast(FilterValue, Integer) + 1) * 100))
        End Function
    End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DropDownAutoFilterItem Class
DropDownAutoFilterItem Members

 

 


Copyright © GrapeCity, inc. All rights reserved.