2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[C++/CLI] DataGridViewとXML読み込み、保存

Last updated at Posted at 2016-12-13

DataGridViewとその情報のXML読み込み保存が
手順がややこしいけどすぐ実装できるのでメモ

#1.画面作成
DataGridViewを追加
DataSetを追加
DataSetは、型指定の無いデータセット

clip00.jpg

clip01.jpg

#2.データ形式設定
##DataSetにテーブルを追加。
プロパティ→Tables(コレクション)を編集
追加でTable1を追加

Table1のカラム追加
	編集したい情報を追加していく
	Column1
		ColumnName = check
		DataType = System.Boolean
	Column2
		ColumnName = name
		DataType = System.String
	Column3
		ColumnName = test

無題.jpg

##DataGridView1とDataSet1の関連付け
DataGridView1のプロパティ
DataSource = dataSet1
DataMember = Table1
clip02.jpg

#3.XML読み書き
##XML保存
dataSet1->WriteXml("test.xml");

##XML読み込み
dataSet1->Clear(); // ReadXMLは追記なので一旦消す
dataSet1->ReadXml("test.xml");

##要素取得
auto tbl = dataSet1->Tables["Table1"];
for(int i = 0; i < tbl->Rows->Count; ++i)
{
auto item = tbl->Rows[i];
MessageBox::Show(
item->ItemArray[0]->ToString() + "/" +
item->ItemArray[1]->ToString() + "/" +
item->ItemArray[2]->ToString() );
}

clip03.jpg

#その他
##サンプルソース
https://github.com/mamesiva64/DataGridViewTest

2
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?