ListBox.SelectionMode プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ListBox.SelectionMode プロパティの意味・解説 

ListBox.SelectionMode プロパティ

ListBox コントロール選択モード取得または設定します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Overridable Property
 SelectionMode As ListSelectionMode
Dim instance As ListBox
Dim value As ListSelectionMode

value = instance.SelectionMode

instance.SelectionMode = value
public virtual ListSelectionMode SelectionMode { get;
 set; }
public:
virtual property ListSelectionMode SelectionMode {
    ListSelectionMode get ();
    void set (ListSelectionMode value);
}
/** @property */
public ListSelectionMode get_SelectionMode ()

/** @property */
public void set_SelectionMode (ListSelectionMode
 value)
public function get SelectionMode
 () : ListSelectionMode

public function set SelectionMode
 (value : ListSelectionMode)

プロパティ
ListSelectionMode 値の 1 つ既定値Single です。

例外例外
例外種類条件

ArgumentException

指定され選択モードListSelectionMode 値ではありません。

解説解説
使用例使用例

SelectionMode プロパティ使用してユーザーListBox コントロール複数の項目を選択できるようにする方法次の例に示します

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<html>
<head>

   <script runat="server">

      Sub SubmitBtn_Click(sender As Object,
 e As EventArgs) 

         Message.Text = "You chose: <br>"
         
         ' Iterate through the Items collection of the ListBox and 
         ' display the selected items.
         Dim item As ListItem
         For Each item in
 ListBox1.Items

            If item.Selected Then

               Message.Text &= item.Text & "<br>"

            End If

         Next

      End Sub

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form runat=server>

      Select items from the list and click
 Submit. <br>

      <asp:ListBox id="ListBox1" 
           Rows="6"
           Width="100px"
           SelectionMode="Multiple" 
           runat="server">

         <asp:ListItem Selected="True">Item
 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>

      </asp:ListBox>

      <br><br>

      <asp:button id="Button1"
           Text="Submit" 
           OnClick="SubmitBtn_Click" 
           runat="server" />

      <br><br>
        
      <asp:Label id="Message" 
           runat="server"/>
        
   </form>

</body>
</html>

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

   <script runat="server">

      void SubmitBtn_Click(Object sender, EventArgs e) 
      {

         Message.Text = "You chose: <br>";
         
         // Iterate through the Items collection of the ListBox and
 
         // display the selected items.
         foreach (ListItem item in ListBox1.Items)
         {

            if(item.Selected)
            {

               Message.Text += item.Text + "<br>";

            }

         }

      }

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form runat=server>

      Select items from the list and click Submit. <br>

      <asp:ListBox id="ListBox1" 
           Rows="6"
           Width="100px"
           SelectionMode="Multiple" 
           runat="server">

         <asp:ListItem Selected="True">Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>

      </asp:ListBox>

      <br><br>

      <asp:button id="Button1"
           Text="Submit" 
           OnClick="SubmitBtn_Click" 
           runat="server" />

      <br><br>
        
      <asp:Label id="Message" 
           runat="server"/>
        
   </form>

</body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ListBox.SelectionMode プロパティ

ListBox で項目を選択する方法取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Overridable Property
 SelectionMode As SelectionMode
Dim instance As ListBox
Dim value As SelectionMode

value = instance.SelectionMode

instance.SelectionMode = value
public virtual SelectionMode SelectionMode { get;
 set; }
public:
virtual property SelectionMode SelectionMode {
    SelectionMode get ();
    void set (SelectionMode value);
}
/** @property */
public SelectionMode get_SelectionMode ()

/** @property */
public void set_SelectionMode (SelectionMode
 value)
public function get SelectionMode
 () : SelectionMode

public function set SelectionMode
 (value : SelectionMode)

プロパティ
SelectionMode 値の 1 つ既定値SelectionMode.One です。

例外例外
例外種類条件

InvalidEnumArgumentException

代入された値が、SelectionMode 値ではありません。

解説解説

SelectionMode プロパティ使用すると、ユーザーListBox 内で一度選択できる項目数や、複数の項目を選択する方法指定できますSelectionMode プロパティSelectionMode.MultiExtended設定されている場合は、Shift キー押しながらマウスクリックするか、Shift キー押しながら方向キー (↑、↓、←、および→) の 1 つを押すと、前に選択した項目から現在選択している項目までを選択できますCtrl キー押しながらマウスクリックすると、リスト内の項目を選択または選択解除できます。このプロパティSelectionMode.MultiSimple設定されている場合は、マウスクリックするか、Space キーを押すと、リスト内の項目を選択または選択解除できます

使用例使用例

GetSelected メソッド使用して ListBox 内のどの項目が選択されているかを判別し、現在選択されていない項目を選択して、現在選択されている項目の選択解除する方法次のコード例示します。この例では、SelectionMode プロパティ使用して ListBox複数の項目の選択許可する方法と、Sorted プロパティ使用して ListBox 内の項目を自動的に並べ替える方法についても示します。この例では、listBox1 という名前の ListBoxフォーム追加されており、この例で定義されている InitializeMyListBox メソッドフォームLoad イベントから呼び出される必要があります

Private Sub InitializeMyListBox()
   ' Add items to the ListBox.
   listBox1.Items.Add("A")
   listBox1.Items.Add("C")
   listBox1.Items.Add("E")
   listBox1.Items.Add("F")
   listBox1.Items.Add("G")
   listBox1.Items.Add("D")
   listBox1.Items.Add("B")

   ' Sort all items added previously.
   listBox1.Sorted = True

   ' Set the SelectionMode to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended

   ' Select three initial items from the list.
   listBox1.SetSelected(0, True)
   listBox1.SetSelected(2, True)
   listBox1.SetSelected(4, True)

   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub

Private Sub InvertMySelection()

   Dim x As Integer
   ' Loop through all items the ListBox.
   For x = 0 To listBox1.Items.Count - 1

      ' Determine if the item is selected.
      If listBox1.GetSelected(x) = True Then
         ' Deselect all items that are selected.
         listBox1.SetSelected(x, False)
      Else
         ' Select all items that are not selected.
         listBox1.SetSelected(x, True)
      End If
   Next x
   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub
private void InitializeMyListBox()
{
   // Add items to the ListBox.
   listBox1.Items.Add("A");
   listBox1.Items.Add("C");
   listBox1.Items.Add("E");
   listBox1.Items.Add("F");
   listBox1.Items.Add("G");
   listBox1.Items.Add("D");
   listBox1.Items.Add("B");

   // Sort all items added previously.
   listBox1.Sorted = true;

   // Set the SelectionMode to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended;

   // Select three initial items from the list.
   listBox1.SetSelected(0,true);
   listBox1.SetSelected(2,true);
   listBox1.SetSelected(4,true);

   // Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex=0;
}

private void InvertMySelection()
{
   // Loop through all items the ListBox.
   for (int x = 0; x < listBox1.Items.Count;
 x++)
   {
      // Determine if the item is selected.
      if(listBox1.GetSelected(x) == true)
         // Deselect all items that are selected.
         listBox1.SetSelected(x,false);      
      else
         // Select all items that are not selected.
         listBox1.SetSelected(x,true);
   }
   // Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex=0;
}
private:
   void InitializeMyListBox()
   {
      // Add items to the ListBox.
      listBox1->Items->Add( "A" );
      listBox1->Items->Add( "C" );
      listBox1->Items->Add( "E" );
      listBox1->Items->Add( "F" );
      listBox1->Items->Add( "G" );
      listBox1->Items->Add( "D" );
      listBox1->Items->Add( "B" );

      // Sort all items added previously.
      listBox1->Sorted = true;

      // Set the SelectionMode to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Select three initial items from the list.
      listBox1->SetSelected( 0, true );
      listBox1->SetSelected( 2, true );
      listBox1->SetSelected( 4, true );

      // Force the ListBox to scroll back to the top of the list.
      listBox1->TopIndex = 0;
   }

   void InvertMySelection()
   {
      // Loop through all items the ListBox.
      for ( int x = 0; x < listBox1->Items->Count;
 x++ )
      {
         // Select all items that are not selected,
         // deselect all items that are selected.
         listBox1->SetSelected( x,  !listBox1->GetSelected( x ) );
      }
      listBox1->TopIndex = 0;
   }
private void InitializeMyListBox()
{
    // Add items to the ListBox.
    listBox1.get_Items().Add("A");
    listBox1.get_Items().Add("C");
    listBox1.get_Items().Add("E");
    listBox1.get_Items().Add("F");
    listBox1.get_Items().Add("G");
    listBox1.get_Items().Add("D");
    listBox1.get_Items().Add("B");

    // Sort all items added previously.
    listBox1.set_Sorted(true);

    // Set the SelectionMode to select multiple items.
    listBox1.set_SelectionMode(SelectionMode.MultiExtended);

    // Select three initial items from the list.
    listBox1.SetSelected(0, true);
    listBox1.SetSelected(2, true);
    listBox1.SetSelected(4, true);

    // Force the ListBox to scroll back to the top of the list.
    listBox1.set_TopIndex(0);
} //InitializeMyListBox

private void InvertMySelection()
{
    // Loop through all items the ListBox.
    for (int x = 0; x < listBox1.get_Items().get_Count();
 x++) {
        // Determine if the item is selected.
        if (listBox1.GetSelected(x) == true)
 {
            // Deselect all items that are selected.
            listBox1.SetSelected(x, false);
        }        
        else {
            // Select all items that are not selected.
            listBox1.SetSelected(x, true);
        }
    }
    // Force the ListBox to scroll back to the top of the list.
    listBox1.set_TopIndex(0);
} //InvertMySelection
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ListBox.SelectionMode プロパティ」の関連用語

ListBox.SelectionMode プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ListBox.SelectionMode プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS