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

ListItemCollectionクラスのRemoveメソッドの例を次に示します。 Web ページには、ListBoxリスト 項目が含まれるコントロールと、 という名前DeleteのコントロールがTextBox含まれています。 ユーザーは、削除する項目のテキストをコントロールに TextBox 入力します。 コントロールのイベント ハンドラーは ClickButton1 選択した項目を 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 メソッドを使用します。 このメソッドは、パラメーター テキストを ListItem 使用して オブジェクトを item 作成し、それを ListItem コレクションから削除します。 指定したitemテキストは、プロパティと既存ListItemのオブジェクトのテキストと正確に一致Valueする必要があります。それ以外の場合、項目は削除されません。

こちらもご覧ください

適用対象

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 作成、コレクションへの項目の追加、コレクションからの項目の削除を示します。 この例では、 ListItemCollection という名前listBoxDataの が コントロールのデータ ソースListBoxとして使用され、 というListBox1名前ddBoxDataListItemCollection が という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 するには、 メソッドを使用します。 メソッドのこの実装は、 パラメーターで指定された をListItemitem受け取り、コレクションから削除します。

こちらもご覧ください

適用対象