本文共 1523 字,大约阅读时间需要 5 分钟。
书上的一段话,没有深入介绍呀。这才是我感兴趣的。
。。。基要以小型网格显示只读值或者使用户能够编辑具有数百万条记录的表,DataGridView控件将提供可以方便地进行编程以及有效地利用内存的解决方案。。。。。。
BUT,后来书上都没有讲的。。
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 WindowsFormsApplication713 {14 public partial class Form1 : Form15 {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 }
转载地址:http://xbpsl.baihongyu.com/