1. 選擇控制項"DataGridView",使用滑鼠拖拉至[設計]。
2. 點選"編集資料行..."。
3. 增加第一行資料欄位,在"名稱"欄位與"標題文字"欄位輸入名稱。
4. 增加第二行資料欄位,在"名稱"欄位與"標題文字"欄位輸入名稱。
5. 可以看到在"選取的資料行"中增加了兩個欄位,之後按"確定"。
6. 程式設計如下。
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
| using System;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) { dataGridView1.Rows.Add(new Object[] { "Black tea", 25 }); dataGridView1.Rows.Add(new Object[] { "Green tea", 20 }); } }} |






沒有留言:
張貼留言