MenuItemCollection.RemoveAt(Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 MenuItem 개체에서 MenuItemCollection 지정된 인덱스 위치에 있는 개체를 제거합니다.
public:
void RemoveAt(int index);
public void RemoveAt(int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
매개 변수
- index
- Int32
제거할 메뉴 항목의 인덱스 위치(0부터 시작)입니다.
예제
다음 코드 예제에서는 메서드를 사용 하 여 RemoveAt 프로그래밍 방식으로 지정 된 인덱스 위치에 있는 개체에서 MenuItem 개체를 제거 MenuItemCollection 하는 방법을 보여 줍니다.
<%@ 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)
{
if (!IsPostBack)
{
// Retrieve the root menu item from the Items
// collection of the Menu control.
MenuItem homeMenuItem = NavigationMenu.Items[0];
// Remove the submenu item at index 0.
homeMenuItem.ChildItems.RemoveAt(0);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemCollection RemoveAt Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemCollection RemoveAt Example</h3>
<asp:menu id="NavigationMenu"
orientation="Vertical"
target="_blank"
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</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)
If Not IsPostBack Then
' Retrieve the root menu item from the Items
' collection of the Menu control.
Dim homeMenuItem As MenuItem = NavigationMenu.Items(0)
' Remove the submenu item at index 0.
homeMenuItem.ChildItems.RemoveAt(0)
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemCollection RemoveAt Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemCollection RemoveAt Example</h3>
<asp:menu id="NavigationMenu"
orientation="Vertical"
target="_blank"
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
설명
이 메서드를 RemoveAt 사용하여 컬렉션에서 MenuItem 지정된 인덱스 위치에 있는 개체를 제거합니다. 그런 다음 해당 메뉴 항목을 따르는 모든 항목이 위로 이동하여 빈 위치를 채웁니다. 이동된 항목의 인덱스도 업데이트됩니다.
메모
개체는 MenuItemCollection null 값과 중복 개체를 MenuItem 포함할 수 있습니다.
또는 메서드를 사용하여 MenuItem 특정 Remove 개체를 제거할 수 있습니다. 메서드를 사용하여 Clear 컬렉션에서 모든 메뉴 항목을 제거할 수도 있습니다.