ListControl クラスとは? わかりやすく解説

ListControl クラス

すべてのリスト型コントロールに共通なプロパティメソッド、およびイベント定義する抽象基本クラス役割果たします

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

<ControlValuePropertyAttribute("SelectedValue")>
 _
Public MustInherit Class
 ListControl
    Inherits DataBoundControl
    Implements IEditableTextControl, ITextControl
[ControlValuePropertyAttribute("SelectedValue")] 
public abstract class ListControl : DataBoundControl,
 IEditableTextControl, ITextControl
[ControlValuePropertyAttribute(L"SelectedValue")] 
public ref class ListControl abstract : public
 DataBoundControl, IEditableTextControl, ITextControl
/** @attribute ControlValuePropertyAttribute("SelectedValue") */ 
public abstract class ListControl extends DataBoundControl
 implements IEditableTextControl, ITextControl
ControlValuePropertyAttribute("SelectedValue") 
public abstract class ListControl extends
 DataBoundControl implements IEditableTextControl, ITextControl
解説解説

ListControl 抽象クラスインスタンス直接作成できません。その代わりに、共通の基本機能提供するために、このクラスは CheckBoxList、DropDownListListBox、RadioButtonList などの他のクラスによって継承されます。

ListControl クラスプロパティ使用すると、リスト コントロール作成するデータソース指定できます。DataSource プロパティ使用してリスト コントロール連結するデータ ソース指定しますデータ ソース複数テーブル含まれる場合は、DataMember プロパティ使用するテーブル指定します。DataTextField プロパティと DataValueField プロパティそれぞれ個別設定すると、リスト コントロール内の項目の ListItem.Text プロパティと ListItem.Value プロパティに、データ ソース内のフィールド個別連結できますリスト コントロール内の各項目に表示されるテキストは、DataTextFormatString プロパティ書式設定ます。

リスト コントロール内に表示されている項目はすべて、Items コレクション格納されています。SelectedIndex プロパティ使用すると、リスト コントロール内の選択されている項目のインデックスプログラムによって指定または確認できます選択されている項目のプロパティアクセスするには、SelectedItem を使用します

ListControl クラスは SelectedIndexChanged イベント提供します。このイベントは、リスト コントロール内の選択項目がサーバーへのポスト間で変更され場合発生します。これにより、このイベントカスタム ハンドラ作成できますイベント処理詳細については、「イベント利用」を参照してください

ListControl クラスは、その他のコントロールテンプレート モード派生したリスト型コントロール使用できるように、IEditableTextControl インターフェイス実装ます。

使用例使用例

ListBox コントロール内の項目を選択する方法次のコード例示します。項目がテキスト ボックス見つかった場合は、項目が選択され選択した項目の名前を示すメッセージ表示されます。項目が見つからなかった場合、項目は選択されず、項目が見つからなかったことを示すメッセージ表示されます。

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

<html> 

<head>

   <script runat="server">

      Sub Button_Click(sender As Object,
 e As EventArgs)

         ' Perform this operation in a try-catch block in case the item
 is not found.
         Try
   
            List.SelectedValue = ItemTextBox.Text
            MessageLabel.Text = "You selected " &
 List.SelectedValue + "."
        
         Catch ex As Exception
     
            List.SelectedValue = Nothing         
            MessageLabel.Text = "Item not found in ListBox control."
     
         End Try
             
      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> ListControl SelectedValue Example </h3>
 
      <asp:ListBox ID="List"
           runat="server">

         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>

      </asp:ListBox>

      <hr>

      Enter the value of the item to select:
 <br>
      <asp:TextBox ID="ItemTextBox"
           MaxLength="6"
           Text="Item 1"
           runat="server"/>

      &nbsp;&nbsp;

      <asp:Button ID="SelectButton"
           Text="Select Item"
           OnClick="Button_Click"
           runat="server"/>

      <br><br>

      <asp:Label ID="MessageLabel"
           runat="server"/>     

   </form>

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

<html> 

<head>

   <script runat="server">

      void Button_Click(Object sender, EventArgs e)
      {

         // Perform this operation in a try-catch block in case the
 item is not found.
         try
         {
            List.SelectedValue = ItemTextBox.Text;
            MessageLabel.Text = "You selected " + List.SelectedValue +
 ".";
         }
         catch (Exception ex)
         {
            List.SelectedValue = null;
            MessageLabel.Text = "Item not found in ListBox
 control.";
         }
             
      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> ListControl SelectedValue Example </h3>
 
      <asp:ListBox ID="List"
           runat="server">

         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>

      </asp:ListBox>

      <hr>

      Enter the value of the item to select: <br>
      <asp:TextBox ID="ItemTextBox"
           MaxLength="6"
           Text="Item 1"
           runat="server"/>

      &nbsp;&nbsp;

      <asp:Button ID="SelectButton"
           Text="Select Item"
           OnClick="Button_Click"
           runat="server"/>

      <br><br>

      <asp:Label ID="MessageLabel"
           runat="server"/>     

   </form>

</body>
</html>
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.BaseDataBoundControl
         System.Web.UI.WebControls.DataBoundControl
          System.Web.UI.WebControls.ListControl
             System.Web.UI.WebControls.BulletedList
             System.Web.UI.WebControls.CheckBoxList
             System.Web.UI.WebControls.DropDownList
             System.Web.UI.WebControls.ListBox
             System.Web.UI.WebControls.RadioButtonList
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ListControl メンバ
System.Web.UI.WebControls 名前空間
CheckBoxList クラス
DropDownList クラス
ListBox クラス
RadioButtonList
ListItem

ListControl クラス

ListBox クラスおよび ComboBox クラスメンバの共通の実装提供します

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

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public MustInherit Class
 ListControl
    Inherits Control
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public abstract class ListControl : Control
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class ListControl abstract : public
 Control
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public abstract class ListControl extends Control
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public abstract class ListControl extends
 Control
解説解説

ListControl クラスは、ListBox コントロールおよび ComboBox コントロールの共通要素実装提供します

データ連結 ListBox または ComboBoxユーザーに主に関係のあるプロパティは、DataSource、DisplayMember、SelectedValue、ValueMember の各プロパティです。

使用例使用例

ListBox クラスによって実装された ListControl クラスDataSourceDisplayMemberValueMember、および SelectedValue の各メンバ使用方法を示す、アプリケーション全体コード例次に示します。この例では、ArrayListリスト ボックス読み込みます。ユーザーリスト ボックスの項目を選択すると、選択した値を使用して選択した項目に関連付けられているデータ返されます。

Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections

Public Class USState
   Private myShortName As String
   Private myLongName As String
   
   Public Sub New(strLongName
 As String, strShortName As
 String)
      Me.myShortName = strShortName
      Me.myLongName = strLongName
   End Sub 'New
   
   Public ReadOnly Property
 ShortName() As String
      Get
         Return myShortName
      End Get
   End Property
   
   Public ReadOnly Property
 LongName() As String
      Get
         Return myLongName
      End Get
   End Property
   
   Public Overrides Function
 ToString() As String
      Return Me.ShortName + "
 - " + Me.LongName
   End Function 'ToString
End Class 'USState


Public Class ListBoxSample3
   Inherits Form
   Private ListBox1 As New
 ListBox()
   Private textBox1 As New
 TextBox()
   
   <STAThread()>  _
   Shared Sub Main()
      Application.Run(New ListBoxSample3())
   End Sub 'Main
   
   Public Sub New()
      Me.ClientSize = New Size(292, 181)
      Me.Text = "ListBox Sample3"
      ListBox1.Location = New Point(24, 16)
      ListBox1.Name = "ListBox1"
      ListBox1.Size = New Size(232, 130)
      textBox1.Location = New Point(24, 160)
      textBox1.Name = "textBox1"
      textBox1.Size = New Size(240, 24)
      Me.Controls.AddRange(New Control() {ListBox1,
 textBox1})
      
      ' Populates the list box using DataSource. 
      ' DisplayMember is used to display just the long name of each
 state.
      Dim USStates As New
 ArrayList()
      USStates.Add(New USState("Alabama",
 "AL"))
      USStates.Add(New USState("Washington",
 "WA"))
      USStates.Add(New USState("West Virginia",
 "WV"))
      USStates.Add(New USState("Wisconsin",
 "WI"))
      USStates.Add(New USState("Wyoming",
 "WY"))
      AddHandler ListBox1.SelectedValueChanged, AddressOf
 ListBox1_SelectedValueChanged
      ListBox1.DataSource = USStates
      ListBox1.DisplayMember = "LongName"
      ListBox1.ValueMember = "ShortName"
   End Sub 'New
   
   Private Sub InitializeComponent()
   End Sub 'InitializeComponent
   
   Private Sub ListBox1_SelectedValueChanged(sender
 As Object, e As EventArgs)
      If ListBox1.SelectedIndex <> - 1 Then
         textBox1.Text = ListBox1.SelectedValue.ToString()
      End If
   End Sub 'ListBox1_SelectedValueChanged
End Class 'ListBoxSample3
using System;
using System.Windows.Forms ;
using System.Drawing ;
using System.Collections ;


namespace MyListControlSample
{

    public class USState
    {
        private string myShortName ;
        private string myLongName ;
    
        public  USState(string strLongName,
 string strShortName)
        {

            this.myShortName = strShortName;
            this.myLongName = strLongName;
        }

        public string ShortName
        {
            get
            {
                return myShortName;
            }
        }

        public string LongName
        {
        
            get
            {
                return myLongName ;
            }
        }

        public override string ToString()
        {
            return this.ShortName + "
 - " + this.LongName;
        }
    }

    public class ListBoxSample3:Form
    {
        private ListBox ListBox1 = new ListBox();
        private TextBox textBox1 = new TextBox()
 ;
        
        [STAThread]
        static void Main() 
        {
            Application.Run(new ListBoxSample3()) ;
        }

        public ListBoxSample3()
        {
        
            this.ClientSize = new Size(292,
 181) ;
            this.Text = "ListBox Sample3" ;

            ListBox1.Location = new Point(24, 16) ;
            ListBox1.Name = "ListBox1" ;
            ListBox1.Size = new Size(232, 130) ;
            


            textBox1.Location = new Point(24, 160) ;
            textBox1.Name = "textBox1" ;
            textBox1.Size = new Size(240, 24) ;
            this.Controls.AddRange(new Control[]
 {ListBox1, textBox1}) ;

            // Populates the list box using DataSource. 
            // DisplayMember is used to display just the long name of
 each state.
            ArrayList USStates = new ArrayList()    ;
            USStates.Add(new USState("Alabama", "AL"));
            USStates.Add(new USState("Washington", "WA"))
  ; 
            USStates.Add(new USState("West Virginia",
 "WV"));
            USStates.Add(new USState("Wisconsin", "WI"))
 ;
            USStates.Add(new USState("Wyoming", "WY"));

            ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
            ListBox1.DataSource = USStates ;
            ListBox1.DisplayMember = "LongName"      ;
            ListBox1.ValueMember = "ShortName" ;

        }
        private void InitializeComponent()
        {
        
        }

        private void ListBox1_SelectedValueChanged(object
 sender, EventArgs e)
        {
            if (ListBox1.SelectedIndex != -1)
                textBox1.Text = ListBox1.SelectedValue.ToString();
        }
    }
}
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Collections;
public ref class USState
{
private:
   String^ myShortName;
   String^ myLongName;

public:
   USState( String^ strLongName, String^ strShortName )
   {
      this->myShortName = strShortName;
      this->myLongName = strLongName;
   }

   property String^ ShortName 
   {
      String^ get()
      {
         return myShortName;
      }
   }

   property String^ LongName 
   {
      String^ get()
      {
         return myLongName;
      }

   }
   virtual String^ ToString() override
   {
      return String::Concat( this->ShortName,
 " - ", this->LongName );
   }
};

public ref class ListBoxSample3: public
 Form
{
private:
   ListBox^ ListBox1;
   TextBox^ textBox1;

public:
   ListBoxSample3()
   {
      ListBox1 = gcnew ListBox;
      textBox1 = gcnew TextBox;
      this->ClientSize = System::Drawing::Size( 292, 181 );
      this->Text = "ListBox Sample3";
      ListBox1->Location = Point(24,16);
      ListBox1->Name = "ListBox1";
      ListBox1->Size = System::Drawing::Size( 232, 130 );
      textBox1->Location = Point(24,160);
      textBox1->Name = "textBox1";
      textBox1->Size = System::Drawing::Size( 240, 24 );
      array<Control^>^temp2 = {ListBox1,textBox1};
      this->Controls->AddRange( temp2 );
      
      // Populates the list box using DataSource. 
      // DisplayMember is used to display just the long name of each
 state.
      ArrayList^ USStates = gcnew ArrayList;
      USStates->Add( gcnew USState( "Alabama","AL" ) );
      USStates->Add( gcnew USState( "Washington","WA" ) );
      USStates->Add( gcnew USState( "West Virginia","WV" )
 );
      USStates->Add( gcnew USState( "Wisconsin","WI" ) );
      USStates->Add( gcnew USState( "Wyoming","WY" ) );
      ListBox1->SelectedValueChanged += gcnew EventHandler( this,
 &ListBoxSample3::ListBox1_SelectedValueChanged );
      ListBox1->DataSource = USStates;
      ListBox1->DisplayMember = "LongName";
      ListBox1->ValueMember = "ShortName";
   }

   void InitializeComponent(){}

private:

   void ListBox1_SelectedValueChanged( Object^ /*sender*/, EventArgs^
 /*e*/ )
   {
      if ( ListBox1->SelectedIndex != -1 )
            textBox1->Text = ListBox1->SelectedValue->ToString();
   }
};

[STAThread]
int main()
{
   Application::Run( gcnew ListBoxSample3 );
}
package MyListControlSample;

import System.*;
import System.Windows.Forms.*;
import System.Drawing.*;
import System.Collections.*;

public class USState
{
    private String myShortName;
    private String myLongName;

    public USState(String strLongName, String strShortName)
    {
        this.myShortName = strShortName;
        this.myLongName = strLongName;
    } //USState

    /** @property
     */
    public String get_ShortName()
    {
        return myShortName;
    }//get_ShortName

    /** @property 
     */
    public String get_LongName()
    {
        return myLongName;
    }//get_LongName

    public String ToString()
    {
        return this.get_ShortName() + "
 - " + this.get_LongName();
    } //ToString
} //USState

public class ListBoxSample3 extends Form
{
    private ListBox listBox1 = new ListBox();
    private TextBox textBox1 = new TextBox();

    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        Application.Run(new ListBoxSample3());
    } //main

    public ListBoxSample3()
    {
        this.set_ClientSize(new Size(292, 181));
        this.set_Text("ListBox Sample3");

        listBox1.set_Location(new Point(24, 16));
        listBox1.set_Name("ListBox1");
        listBox1.set_Size(new Size(232, 130));
        textBox1.set_Location(new Point(24, 160));
        textBox1.set_Name("textBox1");
        textBox1.set_Size(new Size(240, 24));
        this.get_Controls().AddRange(new Control[]
 { listBox1, textBox1 });

        // Populates the list box using DataSource. 
        // DisplayMember is used to display just the long name of each
 state.
        ArrayList uSStates = new ArrayList();
        uSStates.Add(new USState("Alabama", "AL"));
        uSStates.Add(new USState("Washington", "WA"));
        uSStates.Add(new USState("West Virginia", "WV"));
        uSStates.Add(new USState("Wisconsin", "WI"));
        uSStates.Add(new USState("Wyoming", "WY"));

        listBox1.add_SelectedValueChanged(
            new EventHandler(listBox1_SelectedValueChanged));
        listBox1.set_DataSource(uSStates);
        listBox1.set_DisplayMember("LongName");
        listBox1.set_ValueMember("ShortName");
    } //ListBoxSample3
    
    private void InitializeComponent()
    {
    } //InitializeComponent

    private void listBox1_SelectedValueChanged(Object
 sender, EventArgs e)
    {
        if (listBox1.get_SelectedIndex() != -1) {
            textBox1.set_Text(listBox1.get_SelectedValue().ToString());
        }
    } //listBox1_SelectedValueChanged
} //ListBoxSample3 
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.ListControl
           System.Windows.Forms.ComboBox
           System.Windows.Forms.ListBox
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「ListControl クラス」の関連用語

ListControl クラスのお隣キーワード
検索ランキング

   

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



ListControl クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS