[GcSpreadGrid] ドロップダウンカレンダーに休日を設定する方法

文書番号 : 85083     文書種別 : 使用方法     登録日 : 2020/05/07     最終更新日 : 2020/05/07
文書を印刷する
対象製品
SPREAD for WPF 3.0J
詳細
日付時刻型セルのドロップダウンカレンダーに休日を設定するには、HolidaySettingを使用します。
休日は、XAMLで設定する方法とC#/VBで設定する方法があります。

以下は、日曜日を休業日にし、2月19日を休日に設定する例です。


XAMLのみで設定する場合

◎サンプルコード(XAML)
<sg:GcSpreadGrid Name="gcSpreadGrid1">
    <sg:GcSpreadGrid.Resources>
        <sg:HolidaySetting x:Key="MyHoliday">
            <sg:WeeklyHoliday DayOfWeek="Sunday" HolidayOverridePolicy="NextWorkday" WeekInMonth="All" />
            <sg:Holiday StartMonth="2" StartDay="19" EndMonth="2" EndDay="19" HolidayName="創立記念日"/>
        </sg:HolidaySetting>
        <sg:CalendarDayButtonStyleSelector x:Key="MyDayStyle">
            <sg:CalendarDayButtonStyleSelector.Conditions>
                <sg:DayOfWeekCondition DayOfWeek="Sunday">
                    <sg:DayOfWeekCondition.Setters>
                        <sg:SelectorSetter Property="Foreground" Value="Red"/>
                    </sg:DayOfWeekCondition.Setters>
                </sg:DayOfWeekCondition>
                <sg:PropertyCondition Property="IsHoliday" Value="true">
                    <sg:PropertyCondition.Setters>
                        <sg:SelectorSetter Property="Foreground" Value="Red"/>                               
                    </sg:PropertyCondition.Setters>
                </sg:PropertyCondition>
            </sg:CalendarDayButtonStyleSelector.Conditions>
        </sg:CalendarDayButtonStyleSelector>
        <Style TargetType="sg:DropDownCalendarEditElement">
            <Setter Property="HolidaySetting" Value="{StaticResource MyHoliday}"/>
            <Setter Property="CalendarDayButtonStyleSelector" Value="{StaticResource MyDayStyle}"/>                   
        </Style>
    </sg:GcSpreadGrid.Resources>
    <sg:GcSpreadGrid.Columns>
        <sg:Column>
            <sg:Column.CellType>
                <sg:DateTimeCellType />
            </sg:Column.CellType>
        </sg:Column>
    </sg:GcSpreadGrid.Columns>
</sg:GcSpreadGrid>


スタイルをXAMLで設定し、休日をC#/VBで動的に設定する場合

◎サンプルコード(XAML)
<sg:GcSpreadGrid Name="gcSpreadGrid1">
    <sg:GcSpreadGrid.Resources>
        <sg:HolidaySetting x:Key="MyHoliday"/>
        <sg:CalendarDayButtonStyleSelector x:Key="MyDayStyle">
            <sg:CalendarDayButtonStyleSelector.Conditions>
                <sg:DayOfWeekCondition DayOfWeek="Sunday">
                    <sg:DayOfWeekCondition.Setters>
                        <sg:SelectorSetter Property="Foreground" Value="Red"/>
                    </sg:DayOfWeekCondition.Setters>
                </sg:DayOfWeekCondition>
                <sg:PropertyCondition Property="IsHoliday" Value="true">
                    <sg:PropertyCondition.Setters>
                        <sg:SelectorSetter Property="Foreground" Value="Red"/>
                    </sg:PropertyCondition.Setters>
                </sg:PropertyCondition>
            </sg:CalendarDayButtonStyleSelector.Conditions>
        </sg:CalendarDayButtonStyleSelector>
        <Style TargetType="sg:DropDownCalendarEditElement">
            <Setter Property="HolidaySetting" Value="{StaticResource MyHoliday}"/>
            <Setter Property="CalendarDayButtonStyleSelector" Value="{StaticResource MyDayStyle}"/>
        </Style>
    </sg:GcSpreadGrid.Resources>
</sg:GcSpreadGrid>

◎サンプルコード(VB)
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
    Dim dt As GrapeCity.Windows.SpreadGrid.DateTimeCellType = New GrapeCity.Windows.SpreadGrid.DateTimeCellType
    gcSpreadGrid1.Columns(0).CellType = dt

    Dim holidays As GrapeCity.Windows.SpreadGrid.Editors.HolidaySetting = CType(Me.gcSpreadGrid1.FindResource("MyHoliday"), GrapeCity.Windows.SpreadGrid.Editors.HolidaySetting)

    Dim holiday1 As GrapeCity.Windows.SpreadGrid.Editors.WeeklyHoliday = New GrapeCity.Windows.SpreadGrid.Editors.WeeklyHoliday
    holiday1.DayOfWeek = System.DayOfWeek.Sunday
    holiday1.HolidayOverridePolicy = GrapeCity.Windows.SpreadGrid.Editors.HolidayOverridePolicy.NextWorkday
    holiday1.WeekInMonth = GrapeCity.Windows.SpreadGrid.Editors.Weeks.All

    Dim holiday2 As GrapeCity.Windows.SpreadGrid.Editors.Holiday = New GrapeCity.Windows.SpreadGrid.Editors.Holiday
    holiday2.StartMonth = 2
    holiday2.StartDay = 19
    holiday2.EndMonth = 2
    holiday2.EndDay = 19
    holiday2.HolidayName = "創立記念日"

    holidays.Holidays.Add(holiday1)
    holidays.Holidays.Add(holiday2)
End Sub

◎サンプルコード(C#)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    GrapeCity.Windows.SpreadGrid.DateTimeCellType dt = new GrapeCity.Windows.SpreadGrid.DateTimeCellType();
    gcSpreadGrid1.Columns[0].CellType = dt;

    var holidays = this.gcSpreadGrid1.FindResource("MyHoliday") as GrapeCity.Windows.SpreadGrid.Editors.HolidaySetting;

    var holiday1 = new GrapeCity.Windows.SpreadGrid.Editors.WeeklyHoliday();
    holiday1.DayOfWeek = System.DayOfWeek.Sunday;
    holiday1.HolidayOverridePolicy = GrapeCity.Windows.SpreadGrid.Editors.HolidayOverridePolicy.NextWorkday;
    holiday1.WeekInMonth = GrapeCity.Windows.SpreadGrid.Editors.Weeks.All;

    var holiday2 = new GrapeCity.Windows.SpreadGrid.Editors.Holiday();
    holiday2.StartMonth = 2;
    holiday2.StartDay = 19;
    holiday2.EndMonth = 2;
    holiday2.EndDay = 19;
    holiday2.HolidayName = "創立記念日";

    holidays.Holidays.Add(holiday1);
    holidays.Holidays.Add(holiday2);
}
キーワード
HowTo