티스토리 뷰
using System;
using System.Data;
using System.Windows.Forms;
namespace GridSample
{
public partial class Form1 : Form
{
private DataSet ourDataSet;
private DataTable myDataTable;
private BindingSource ourBindingSource;
public Form1()
{
InitializeComponent();
InitializeMyComponent();
}
private void InitializeMyComponent()
{
ourDataSet = new DataSet();
myDataTable = new DataTable("Person");
ourBindingSource = new BindingSource();
myDataTable.Columns.Add("Name", typeof(string));
myDataTable.Columns.Add("Age", typeof(int));
myDataTable.Columns.Add("Man", typeof(bool));
myDataTable.Columns["Name"].AllowDBNull = false;
myDataTable.Columns["Name"].Unique = true;
ourDataSet.Tables.Add(myDataTable);
ourDataSet.ReadXml("Person.xml");
ourBindingSource.DataSource = ourDataSet;
ourBindingSource.DataMember = "Person";
this.dataGridView1.DataSource = ourBindingSource;
}
private void toolStripButtonSave_Click(object sender, EventArgs e)
{
this.Validate();
ourBindingSource.EndEdit();
ourDataSet.WriteXml("Person.xml");
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = e.Exception.Message;
e.Cancel = true;
}
}
}
using System.Data;
using System.Windows.Forms;
namespace GridSample
{
public partial class Form1 : Form
{
private DataSet ourDataSet;
private DataTable myDataTable;
private BindingSource ourBindingSource;
public Form1()
{
InitializeComponent();
InitializeMyComponent();
}
private void InitializeMyComponent()
{
ourDataSet = new DataSet();
myDataTable = new DataTable("Person");
ourBindingSource = new BindingSource();
myDataTable.Columns.Add("Name", typeof(string));
myDataTable.Columns.Add("Age", typeof(int));
myDataTable.Columns.Add("Man", typeof(bool));
myDataTable.Columns["Name"].AllowDBNull = false;
myDataTable.Columns["Name"].Unique = true;
ourDataSet.Tables.Add(myDataTable);
ourDataSet.ReadXml("Person.xml");
ourBindingSource.DataSource = ourDataSet;
ourBindingSource.DataMember = "Person";
this.dataGridView1.DataSource = ourBindingSource;
}
private void toolStripButtonSave_Click(object sender, EventArgs e)
{
this.Validate();
ourBindingSource.EndEdit();
ourDataSet.WriteXml("Person.xml");
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = e.Exception.Message;
e.Cancel = true;
}
}
}
Person.xml
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Person>
<Name>Paul</Name>
<Age>40</Age>
<Man>true</Man>
</Person>
<Person>
<Name>Jane</Name>
<Age>41</Age>
<Man>false</Man>
</Person>
<Person>
<Name>Joe</Name>
<Age>36</Age>
<Man>true</Man>
</Person>
<Person>
<Name>Lora</Name>
<Age>21</Age>
</Person>
</NewDataSet>
<NewDataSet>
<Person>
<Name>Paul</Name>
<Age>40</Age>
<Man>true</Man>
</Person>
<Person>
<Name>Jane</Name>
<Age>41</Age>
<Man>false</Man>
</Person>
<Person>
<Name>Joe</Name>
<Age>36</Age>
<Man>true</Man>
</Person>
<Person>
<Name>Lora</Name>
<Age>21</Age>
</Person>
</NewDataSet>
'Code > C#' 카테고리의 다른 글
[C#] SQL Compact & DataGridView Binding Sample (0) | 2008.12.20 |
---|---|
[C#] Object Binding Sample Project (0) | 2008.12.20 |
.NET Compact Framework Project Sample (0) | 2008.08.13 |
Cursor.Position, SetCursorPos, mouse_event 샘플코드 (0) | 2008.04.18 |
Process : Thread를 이용한 메모장에 키 입력하기 (0) | 2008.04.18 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Sample Code
- .net framework
- 애드센스감추기
- download.com
- Phalanger
- AdSense숨기기
- Automation
- iText
- DotNetMagic
- Microsoft
- READYSTATE_COMPLETE
- 스크린캡쳐
- windows
- ScreenHunter
- AxWebBrowser
- Regular Expressions
- 애드센스숨기기
- iTextSharp
- Rollback Rx
- tagREADYSTATE
- WinAutomation
- registry
- AdSense감추기
- Service pack
- autohotkey
- 유틸리티
- c#
- java
- jre
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함