CodePanic! > C#.NET Tips > 今ここ
■行を追加する
チェックボックスとテキストボックスを列に持つ
DataGridViewの行を追加する例です。
object型の配列で1行分のデータを用意し
それをRowsコレクションのAdd関数で追加しています。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for(int i = 0; i < 10; i ++)
{
object[] row = { true, "りんご" + i.ToString() };
dataGridView1.Rows.Add(row);
}
}
}
}
Copyright © 2008.07 - shougo suzaki
|