怎样将datagridview中得数据转换到ds中

解决方案 »

  1.   

    初期化的时候,把datagrid的datasource设置到对应的ds上,就不需要事后转换了。
      

  2.   

    如何将一张表绑定到datagridview控件上
      

  3.   

    如何将ds里面的数据绑定到dataGridView中,字段对应
      

  4.   

    http://wenku.baidu.com/view/0f8177eeaeaad1f346933f57.html
      

  5.   

    http://topic.csdn.net/u/20091124/10/ada6f43c-15a4-4177-aeff-5209c3d0f149.html
      

  6.   

    using System;
    using System.Windows.Forms;public enum Title
    {
        King,
        Sir
    };public class EnumsAndComboBox : Form
    {
        private DataGridView dataGridView1 = new DataGridView();
        private BindingSource bindingSource1 = new BindingSource();    public EnumsAndComboBox()
        {
            this.Load += new System.EventHandler(EnumsAndComboBox_Load);
        }    private void EnumsAndComboBox_Load(object sender, System.EventArgs e)
        {
            // Populate the data source.
            bindingSource1.Add(new Knight(Title.King, "Uther", true));
            bindingSource1.Add(new Knight(Title.King, "Arthur", true));
            bindingSource1.Add(new Knight(Title.Sir, "Mordred", false));
            bindingSource1.Add(new Knight(Title.Sir, "Gawain", true));
            bindingSource1.Add(new Knight(Title.Sir, "Galahad", true));        // Initialize the DataGridView.
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.AutoSize = true;
            dataGridView1.DataSource = bindingSource1;        dataGridView1.Columns.Add(CreateComboBoxWithEnums());        // Initialize and add a text box column.
            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "Name";
            column.Name = "Knight";
            dataGridView1.Columns.Add(column);        // Initialize and add a check box column.
            column = new DataGridViewCheckBoxColumn();
            column.DataPropertyName = "GoodGuy";
            column.Name = "Good";
            dataGridView1.Columns.Add(column);        // Initialize the form.
            this.Controls.Add(dataGridView1);
            this.AutoSize = true;
            this.Text = "DataGridView object binding demo";
        }    DataGridViewComboBoxColumn CreateComboBoxWithEnums()
        {
            DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
            combo.DataSource = Enum.GetValues(typeof(Title));
            combo.DataPropertyName = "Title";
            combo.Name = "Title";
            return combo;
        }
        #region "business object"
        private class Knight
        {
            private string hisName;
            private bool good;
            private Title hisTitle;        public Knight(Title title, string name, bool good)
            {
                hisTitle = title;
                hisName = name;
                this.good = good;
            }        public Knight()
            {
                hisTitle = Title.Sir;
                hisName = "<enter name>";
                good = true;
            }        public string Name
            {
                get
                {
                    return hisName;
                }            set
                {
                    hisName = value;
                }
            }        public bool GoodGuy
            {
                get
                {
                    return good;
                }
                set
                {
                    good = value;
                }
            }        public Title Title
            {
                get
                {
                    return hisTitle;
                }
                set
                {
                    hisTitle = value;
                }
            }
        }
        #endregion    [STAThread]
        public static void Main()
        {
            Application.Run(new EnumsAndComboBox());
        }}