110. 체크리스트박스(CheckedListBox)
.NET프로그래밍/WinForm 2009. 8. 28. 14:34 |
==> Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyWinForms
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Controls.FrmCheckedListBox());
}
}
}
==============================================================================================
==> MainForm.cs
// 체크리스트 박스 관련
private void miCheckedListBox_Click(object sender, EventArgs e)
{
// 생성과 동시에 오픈
(new MyWinForms.Controls.FrmCheckedListBox()).Show();
}
==============================================================================================
==> FrmCheckedListBox.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyWinForms.Controls
{
public partial class FrmCheckedListBox : Form
{
public FrmCheckedListBox()
{
InitializeComponent();
}
private void FrmCheckedListBox_Load(object sender, EventArgs e)
{
string[] fav = {"C#", "ASP.NET", "WPF", "Silverlight" };
for (int i = 0; i < fav.Length; i++)
{
// 짝수만 체크된 상태
if (i % 2 != 0)
{
lstFavorites.Items.Add(fav[i], true);
}
else
{
lstFavorites.Items.Add(fav[i]);
}
}
}
private void btnSelect_Click(object sender, EventArgs e)
{
// Input
List<Favorite> lst = new List<Favorite>();
string msg = "";
// Process
for (int i = 0; i < lstFavorites.CheckedItems.Count; i++)
{
lst.Add(new Favorite()
{
Name = lstFavorites.CheckedItems[i].ToString()
});
msg += lstFavorites.CheckedItems[i].ToString();
}
// Output
ctlSelectedList.DataSource = lst; // 배열, 컬렉션, 리스트를 출력할 수 있다.
MessageBox.Show(msg);
}
}
public class Favorite
{
public string Name { get; set; }
}
}
< 실행결과 >
--> '선택'버튼을 누르면 '체크리스트박스'에 체크된 항목이 'MassageBox'와 'DataGridView'에 출력됨.
'.NET프로그래밍 > WinForm' 카테고리의 다른 글
112. 리스트뷰(ListView) (0) | 2009.08.28 |
---|---|
111. PictureBox와 OpenFileDialog를 이용하여 간단한 이미지뷰어(ImageViewer) 만들기 (0) | 2009.08.28 |
109. 창 ( 창 닫기 / 계단식 정렬 / 수평 바둑판 정렬 / 수직 바둑판 정렬 ) (0) | 2009.08.27 |
108. 초간단 웹브라우저 만들기 (0) | 2009.08.27 |
107. StatusStrip에서 NotifyIcon(트레이에 작은 아이콘 표시) / Timer(시간표시) / StatusLabel(레이블로 텍스트 작성) (0) | 2009.08.27 |