반응형
* C# Listview 에 Button, Progressbar, TextBox Control 삽입 예제...
-사용한 컨트롤 : Button 1개, Listview 1개
전체 소스 코드
Form1.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 CSharp_ListView
{
public partial class Form1 : Form
{
//컨트롤 해제 변수...
List<Control> ltControl = new List<Control>();
public Form1()
{
InitializeComponent();
}
void ControlDispose()
{
for (int iCount = 0; iCount < ltControl.Count; iCount++)
{
ltControl[iCount].Dispose();
}
if (ltControl.Count > 0)
{
ltControl.Clear();
}
}
private void button2_Click(object sender, EventArgs e)
{
lvMain.Groups.Clear();
lvMain.Items.Clear();
ControlDispose();
ListViewItem lvi = new ListViewItem();
lvi.Text = "000";
lvi.SubItems.Add("111");
lvi.SubItems.Add("222");
lvi.SubItems.Add("333");
lvMain.Items.Add(lvi);
//객체를 어디에 담았다가 Dispose() 해주기...
//Control In 할 객체 만들기...
ProgressBar pb = new ProgressBar();
pb.Minimum = 0;
pb.Maximum = 100;
pb.Value = 50;
pb.Parent = lvMain;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps = null;
ps = lvMain.Items[0].SubItems[0];
//그리기
Rectangle rt = new Rectangle();
rt = ps.Bounds;
pb.SetBounds(rt.X, rt.Y, 100, rt.Height);
ltControl.Add(pb);
Button bt = new Button();
bt.Text = "In Button1";
bt.Click += new EventHandler(bt_Click);
bt.Parent = lvMain;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps2 = null;
ps2 = lvMain.Items[0].SubItems[1];
//그리기
Rectangle rt2 = new Rectangle();
rt2 = ps2.Bounds;
bt.SetBounds(rt2.X, rt2.Y, rt2.Width, rt2.Height+6);
ltControl.Add(bt);
Button bt2 = new Button();
bt2.Text = "In Button2";
bt2.Click += new EventHandler(bt_Click);
bt2.Parent = lvMain;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps3 = null;
ps3 = lvMain.Items[0].SubItems[2];
//그리기
Rectangle rt3 = new Rectangle();
rt3 = ps3.Bounds;
bt2.SetBounds(rt3.X, rt3.Y, rt3.Width, rt3.Height+6);
ltControl.Add(bt2);
TextBox tb = new TextBox();
tb.Text = "In TextBox";
tb.Parent = lvMain;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps4 = null;
ps4 = lvMain.Items[0].SubItems[3];
//그리기
Rectangle rt4 = new Rectangle();
rt4 = ps4.Bounds;
tb.SetBounds(rt4.X, rt4.Y, rt4.Width, rt4.Height);
ltControl.Add(tb);
}
void bt_Click(object s, EventArgs e)
{
Button bt = s as Button;
MessageBox.Show(bt.Text);
}
}
}
*예제 결과
https://kdsoft-zeros.tistory.com/211
반응형
'C# Programming' 카테고리의 다른 글
[C#] [Control] Listview - BeginUpdate(), EndUpdate() 조회 속도 비교 (0) | 2020.05.21 |
---|---|
[C#] 움직이는 라벨 만들기 (0) | 2020.05.19 |
[C#] [Control] Listview - 그룹화 항목 만들기 (0) | 2020.05.13 |
[C#] EXE File iCon 가져오기 (0) | 2020.05.11 |
[C#] App Configuration - Key & Value 값 읽기 (0) | 2020.05.07 |