文档介绍:IT-Homer 专栏
成功是优点的发挥,失败是缺点的积累! 不为失败找理由,只为成功找
方法……
DataGridView in Windows Forms – Tips, Tricks and Frequently Asked
Questions(FAQ)
分类: SQL Index 2010-03-12 22:34 260人阅读评论(0) 收藏举报
DataGridView control is a Windows Forms control that gives you the ability to customize and
edit tabular data. It gives you number of properties, methods and events to customize its
appearance and behavior. In this article, we will discuss some frequently asked questions and
their solutions. These questions have been collected from a variety of sources including some
newsgroups, MSDN site and a few, answered by me at the MSDN forums.
Tip 1 – Populating a DataGridView
 
In this short snippet, we will populate a DataGridView using the LoadData() method. This
method uses the SqlDataAdapter to populate a DataSet. The table ‘Orders’ in the DataSet is
then bound to the ponent which gives us the flexibility to choose/modify the
data location.
C#
public partial class Form1 : Form
    {
        private SqlDataAdapter da;
        private SqlConnection conn;
        BindingSource bsource = new BindingSource();
        DataSet ds = null;
        string sql;
 
        public Form1()
        {
            ponent();
        }
 
        private void btnLoad_Click(object sender, EventArgs e)
        {
            LoadData();
        }
 
        private void Lo