using System; using System.Collections.Generic; using System.Windows.Forms;
네임 스페이스 WindowsFormsApplication11 { 공공 부분 Form1 클래스 : 양식 { 목록 _items = 새 목록();
public Form1()
{
InitializeComponent();
_items.Add("One");
_items.Add("Two");
_items.Add("Three");
listBox1.DataSource = _items;
}
private void button1_Click(object sender, EventArgs e)
{
// The Add button was clicked.
_items.Add("New item " + DateTime.Now.Second);
// Change the DataSource.
listBox1.DataSource = null;
listBox1.DataSource = _items;
}
private void button2_Click(object sender, EventArgs e)
{
// The Remove button was clicked.
int selectedIndex = listBox1.SelectedIndex;
try
{
// Remove the item in the List.
_items.RemoveAt(selectedIndex);
}
catch
{
}
listBox1.DataSource = null;
listBox1.DataSource = _items;
}
}
}
개인 무효를 Button1_Click (개체 보낸 사람, EventArgs입니다 전자) { //이 추가 버튼을 클릭했다. // ...
button2.Enabled = true;
}
개인 무효 button2_Click (개체 보낸 사람, EventArgs입니다 전자) { //이 제거 버튼을 클릭했다. 대신 목록 상자는 목록보기 사용할 수 있습니다
if (listBox1.Items.Count == 0)
{
button2.Enabled = false;
}
}
Win Forms 또는 ASP.NET? – Canavar
그리고 실제로 질문을 읽으려고 downvoted .... : 한숨 : –
@ Canavar WinForms. @Deviant Downvoted? – Vectovox