书上的一段话,没有深入介绍呀。这才是我感兴趣的。

。。。基要以小型网格显示只读值或者使用户能够编辑具有数百万条记录的表,DataGridView控件将提供可以方便地进行编程以及有效地利用内存的解决方案。。。。。。

BUT,后来书上都没有讲的。。

DataGridView数据控件演示
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11 
12 namespace WindowsFormsApplication7
13 {
14     public partial class Form1 : Form
15     {
16         SqlConnection conn;
17         SqlDataAdapter sda;
18         DataSet ds = null;
19         public Form1()
20         {
21             InitializeComponent();
22         }
23 
24         private void Form1_Load(object sender, EventArgs e)
25         {
26             conn = new SqlConnection("server = .; database = msdb ; uid = A; pwd = B");
27             sda = new SqlDataAdapter("select * from MSdbms_map", conn);
28             ds = new DataSet();
29             sda.Fill(ds, "map");
30             dataGridView1.DataSource = ds.Tables[0];
31             dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
32             dataGridView1.ReadOnly = true;
33             dataGridView1.DefaultCellStyle.SelectionBackColor = Color.DarkRed;
34         }
35 
36         private void button1_Click(object sender, EventArgs e)
37         {
38             string msg = string.Format("第{0}行,第{1}列", dataGridView1.CurrentCell.RowIndex, dataGridView1.CurrentCell.ColumnIndex);
39             label1.Text = "选择的单元格为: " + msg;
40         }
41     }
42 }
DataGridView数据控件演示

DataGridView数据控件演示

相关文章:

  • 2021-07-11
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-02-08
猜你喜欢
  • 2021-06-09
  • 2022-12-23
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2021-07-24
相关资源
相似解决方案