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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.button1.Click +=new EventHandler(button1_Click);
           
//使用ComboBox加入數字1~9

for (int i = 1; i <= 9; i++) { comboBox1.Items.Add(i); comboBox2.Items.Add(i);
//讓起始值固定在數字1, comboBox1.SelectedIndex = 0; comboBox2.SelectedIndex = 0; } } void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable();
//加入column欄位
dt.Columns.Add("Columns1", typeof(int)); dt.Columns.Add("Columns2", typeof(int)); dt.Columns.Add("Columns3", typeof(int));
//DataTable資料來源為dt

dataGridView1.DataSource = dt;

//使用迴圈將數字輸入到DataGridView
for (int i = 1; i <= int.Parse(comboBox1.Text); i++)
{
for (int j = 1; j <= int.Parse(comboBox2.Text); j++)
{
DataRow row;
row = dt.NewRow(); row["Columns1"] = i; row["Columns2"] =j; row["Columns3"] = i*j; dt.Rows.Add(row); } } } } }

 

文章標籤
全站熱搜
創作者介紹
創作者 熊仔 的頭像
熊仔

熊仔的部落格

熊仔 發表在 痞客邦 留言(0) 人氣(394)