次の方法で共有


ListItemCollection.Remove メソッド

定義

コレクションから ListItem を削除します。

オーバーロード

名前 説明
Remove(String)

指定した文字列で表される ListItem をコレクションから削除します。

Remove(ListItem)

指定した ListItem をコレクションから削除します。

Remove(String)

指定した文字列で表される ListItem をコレクションから削除します。

public:
 void Remove(System::String ^ item);
public void Remove(string item);
member this.Remove : string -> unit
Public Sub Remove (item As String)

パラメーター

item
String

コレクションから削除する項目を表す String

次の例では、Remove クラスのListItemCollection メソッドを示します。 Web ページには、一部のリスト 項目を含むListBox コントロールと、Deleteという名前のTextBox コントロールが含まれています。 ユーザーは、削除する項目のテキストを TextBox コントロールに入力します。 Button1 コントロールのClick イベント ハンドラーは、選択した項目をListItemCollection オブジェクトから削除するため、ListBox コントロールから削除します。

ListItem myListItem = new ListItem(Delete.Text.ToLower(),Delete.Text.ToLower());
// Check whether the 'ListItem' is present in the 'ListBox' or not.
if(ItemCollection.Contains(myListItem))
{
   String deleteString=Delete.Text;
   // Delete the listitem entered by the user in textfield.
   ItemCollection.Remove(deleteString.ToLower());
   Message.Text="<font color='green'><b>Deleted Successfully</b></font>";
}
else
{
  Message.Text="<font color='red'><b>No ListItem with the given name is present in the ListBox for deletion.</b></font>";
}               

     Dim myListItem As ListItem = new ListItem(Delete.Text.ToLower(),Delete.Text.ToLower())
     ' Check whether the 'ListItem' is present in the 'ListBox' or not.
     If(ItemCollection.Contains(myListItem)) Then
     
        Dim deleteString As String =Delete.Text
        ' Delete the listitem entered by the user in textfield.
        ItemCollection.Remove(deleteString.ToLower())
        Message.Text="<font color='green'><b>Deleted Successfully</b></font>"
     Else
     
       Message.Text="<font color='red'><b>No ListItem with the given name is present in the ListBox for deletion.</b></font>"
     End If

注釈

Remove メソッドを使用して、コレクションからListItem オブジェクトを削除します。 このメソッドは、item パラメーター テキストを使用してListItem オブジェクトを作成し、そのListItemをコレクションから削除します。 指定した item テキストは、 Value プロパティと既存の ListItem オブジェクトのテキストと正確に一致する必要があります。それ以外の場合、項目は削除されません。

こちらもご覧ください

適用対象

Remove(ListItem)

指定した ListItem をコレクションから削除します。

public:
 void Remove(System::Web::UI::WebControls::ListItem ^ item);
public void Remove(System.Web.UI.WebControls.ListItem item);
member this.Remove : System.Web.UI.WebControls.ListItem -> unit
Public Sub Remove (item As ListItem)

パラメーター

item
ListItem

コレクションから削除する ListItem

次のコード例では、 ListItemCollection オブジェクトの作成、コレクションへの項目の追加、およびコレクションからの項目の削除を示します。 この例では、listBoxData という名前のListItemCollectionListBox1 と呼ばれるListBox コントロールのデータ ソースとして使用され、ddBoxData と呼ばれるListItemCollectionは、DropDownList1 と呼ばれるDropDownList コントロールのデータ ソースとして使用されます。 完全に動作する例でこのコードを表示するには、 WebControl クラスのトピックを参照してください。

//Set the SelectedIndex to -1 so no items are selected.
// The new item will be set as the selected item when it is added.
DropDownList1.SelectedIndex = -1;
// Add the selected item to DropDownList1.
DropDownList1.Items.Add(ListBox1.SelectedItem);
// Delete the selected item from ListBox1.
ListBox1.Items.Remove(ListBox1.SelectedItem);
' Add the selected item to DropDownList1.
DropDownList1.Items.Add(ListBox1.SelectedItem)
' Delete the selected item from ListBox1.
ListBox1.Items.Remove(ListBox1.SelectedItem)

注釈

Remove メソッドを使用して、コレクションからListItemを削除します。 このメソッドの実装では、item パラメーターで指定されたListItemを受け取り、コレクションから削除します。

こちらもご覧ください

適用対象