SelectedDatesCollection クラス

定義

DateTime コントロールで選択した日付を表すCalendar オブジェクトのコレクションをカプセル化します。 このクラスは継承できません。

public ref class SelectedDatesCollection sealed : System::Collections::ICollection
public sealed class SelectedDatesCollection : System.Collections.ICollection
type SelectedDatesCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class SelectedDatesCollection
Implements ICollection
継承
SelectedDatesCollection
実装

次のコード例では、 SelectedDatesCollection クラスをプログラムで使用して、 Calendar コントロールの日付を選択する方法を示します。

<%@ Page Language="C#"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  void Page_Load(Object sender, EventArgs e) 
  {
    DisplayCalendar.VisibleDate = DisplayCalendar.TodaysDate;
  }

  void SelectButton_Click(Object sender, EventArgs e) 
  {

    int current_day = DisplayCalendar.VisibleDate.Day;
    int current_month = DisplayCalendar.VisibleDate.Month;
    int current_year = DisplayCalendar.VisibleDate.Year;

    DisplayCalendar.SelectedDates.Clear();
   
    // Iterate through the current month and add all Wednesdays to the 
    // SelectedDates collection of the Calendar control.
    for (int i = 1; i <= System.DateTime.DaysInMonth(current_year, current_month); i++)
    {
       DateTime currentDate = new DateTime(current_year, current_month, i);
       if (currentDate.DayOfWeek == DayOfWeek.Wednesday)
       {
         DisplayCalendar.SelectedDates.Add(currentDate);
       }
    }

     MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString();
 
  }

  void DisplayCalendar_SelectionChanged(Object sender, EventArgs e) 
  {
    MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString();
  }
 
</script> 
 
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
 
      <asp:calendar id="DisplayCalendar" runat="server"  
        selectionmode="DayWeekMonth" 
        onselectionchanged="DisplayCalendar_SelectionChanged" />
 
      <hr />
 
      <asp:button id="SelectButton"
        text="Select All Weds in Month" 
        onclick="SelectButton_Click"  
        runat="server"/> 
        
      <br/>
 
      <asp:label id="MessageLabel" 
        runat="server" />
 
    </form>
  </body>
</html>
<%@ Page Language="VB"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
 
    DisplayCalendar.VisibleDate = DisplayCalendar.TodaysDate
    
  End Sub

  Sub SelectButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim current_day As Integer = DisplayCalendar.VisibleDate.Day
    Dim current_month As Integer = DisplayCalendar.VisibleDate.Month
    Dim current_year As Integer = DisplayCalendar.VisibleDate.Year

    DisplayCalendar.SelectedDates.Clear()
   
    ' Iterate through the current month and add all Wednesdays to the 
    ' SelectedDates collection of the Calendar control.
    Dim i As Integer
    For i = 1 To System.DateTime.DaysInMonth(current_year, current_month)
    
      Dim currentDate As New DateTime(current_year, current_month, i)
      If currentDate.DayOfWeek = DayOfWeek.Wednesday Then
       
        DisplayCalendar.SelectedDates.Add(currentDate)
        
      End If
      
    Next

    MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString()
 
  End Sub

  Sub DisplayCalendar_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
  
    MessageLabel.Text = "Selection Count = " & DisplayCalendar.SelectedDates.Count.ToString()
  
  End Sub
 
</script> 
 
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
 
      <asp:calendar id="DisplayCalendar" runat="server"  
        selectionmode="DayWeekMonth" 
        onselectionchanged="DisplayCalendar_SelectionChanged" />
 
      <hr />
 
      <asp:button id="SelectButton"
        text="Select All Weds in Month" 
        onclick="SelectButton_Click"  
        runat="server"/> 
        
      <br/>
 
      <asp:label id="MessageLabel" 
        runat="server" />
 
    </form>
  </body>
</html>

注釈

このクラスを使用して、Calendar コントロールで選択した日付を表すSystem.DateTime オブジェクトのコレクションをプログラムで管理します。 このクラスは、通常、コレクションに日付を追加または削除するために使用されます。

このコレクションには、日付全体のみが格納されます。 各 System.DateTime の時間部分が削除されます。 日付は昇順で格納されます。 重複する日付がある場合、コレクションに格納される日付は 1 つだけです。

コンストラクター

名前 説明
SelectedDatesCollection(ArrayList)

指定した日付リストを使用して、 SelectedDatesCollection クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Count

DateTime コレクション内のSelectedDatesCollection オブジェクトの数を取得します。

IsReadOnly

SelectedDatesCollection コレクションが読み取り専用かどうかを示す値を取得します。

IsSynchronized

SelectedDatesCollection コレクションへのアクセスが同期されているかどうかを示す値を取得します (スレッド セーフ)。

Item[Int32]

DateTime コレクション内の指定したインデックス位置にあるSelectedDatesCollection オブジェクトを取得します。

SyncRoot

SelectedDatesCollection コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。

メソッド

名前 説明
Add(DateTime)

指定した DateTime オブジェクトを SelectedDatesCollection コレクションの末尾に追加します。

Clear()

コレクションからすべての DateTime オブジェクトを削除します。

Contains(DateTime)

SelectedDatesCollection コレクションに指定したDateTime オブジェクトが含まれているかどうかを示す値を返します。

CopyTo(Array, Int32)

SelectedDatesCollection コレクションから指定したArrayに、指定したインデックスからアイテムをコピーします。

Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

IEnumerator コレクション内のすべてのDateTime オブジェクトを含む、SelectedDatesCollection実装されたオブジェクトを返します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
Remove(DateTime)

指定した DateTime オブジェクトを SelectedDatesCollection コレクションから削除します。

SelectRange(DateTime, DateTime)

指定した日付範囲を SelectedDatesCollection コレクションに追加します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

拡張メソッド

名前 説明
AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryableに変換します。

Cast<TResult>(IEnumerable)

IEnumerable の要素を指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定した型に基づいて、IEnumerable の要素をフィルター処理します。

適用対象

こちらもご覧ください