Results 1 to 2 of 2

Thread: [2.0] Datagrid versus Datagridview

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    [2.0] Datagrid versus Datagridview

    I keep hearing that datagridviews are the way to go. I am using C# and VS2005. With datagrids I would use datagridtable styles. Is there such a thing with the dgview? If so, how do I convert the code below to use on a dgview?

    Code:
    namespace DocCtrl
    {
        public partial class frmDocMain : Form
        {
            DataGridTableStyle t = new DataGridTableStyle();
            public frmDocMain()
            {
                InitializeComponent();
            }
    
            private void frmDocMain_Load(object sender, EventArgs e)
            {
                sqlDataAdapter1.Fill(dsPers1, "CrseSched");
    
                
                //create dataset
                DataSet oDS = new DataSet();
                //create connection
                SqlConnection myConnection = new SqlConnection();
                myConnection.ConnectionString = "workstation id=S-KG;packet size=4096;integrated security=SSPI;data source=SCE;persist security info=False;initial catalog=DocCtrl";
                myConnection.Open();
                //create dataadapter
                SqlDataAdapter daPers = new SqlDataAdapter();
                SqlCommand myCommand;
                string cmdtext;
                cmdtext = "SELECT * from Doc_Forms where Service_Number like '" + txtSN.Text + "'";
                daPers = new SqlDataAdapter(cmdtext, myConnection);
                daPers.Fill(oDS, "text");
                dgDocs.DataSource = oDS.Tables["text"];
                if (t.MappingName == "text")
                {
    
                }
                else
                {
                    t.MappingName = "text";
    
                    DataGridTextBoxColumn c;
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "ID";
                    c.HeaderText = "ID";
                    c.Width = 0;
                    t.GridColumnStyles.Add(c);
    
                    DataGridBoolColumn d;
                    d = new DataGridBoolColumn();
                    d.MappingName = "Completed";
                    d.HeaderText = "Completed";
                    d.Width = 60;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    d = new DataGridBoolColumn();
                    d.MappingName = "Pers_File";
                    d.HeaderText = "Pers File";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    t.MappingName = "text";
                    d = new DataGridBoolColumn();
                    d.MappingName = "UER";
                    d.HeaderText = "UER";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    d = new DataGridBoolColumn();
                    d.MappingName = "Re_Engagement";
                    d.HeaderText = "Re Engag";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    t.MappingName = "text";
                    d = new DataGridBoolColumn();
                    d.MappingName = "Occupational_Transfer";
                    d.HeaderText = "Occ Trans";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    d = new DataGridBoolColumn();
                    d.MappingName = "Lve_Jacket";
                    d.HeaderText = "Lve Jac";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    t.MappingName = "text";
                    d = new DataGridBoolColumn();
                    d.MappingName = "CF_98";
                    d.HeaderText = "CF98";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    d = new DataGridBoolColumn();
                    d.MappingName = "Promotion";
                    d.HeaderText = "Promo";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    t.MappingName = "text";
                    d = new DataGridBoolColumn();
                    d.MappingName = "CF_459";
                    d.HeaderText = "CF459";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    d = new DataGridBoolColumn();
                    d.MappingName = "STR";
                    d.HeaderText = "Str";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    t.MappingName = "text";
                    d = new DataGridBoolColumn();
                    d.MappingName = "CF_2088";
                    d.HeaderText = "CF2088";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    d = new DataGridBoolColumn();
                    d.MappingName = "Release";
                    d.HeaderText = "Rel";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    t.MappingName = "text";
                    d = new DataGridBoolColumn();
                    d.MappingName = "CF377";
                    d.HeaderText = "CF377";
                    d.Width = 50;
                    d.AllowNull = false;
                    t.GridColumnStyles.Add(d);
    
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "Pass_to";
                    c.HeaderText = "Pass to";
                    c.Width = 70;
                    t.GridColumnStyles.Add(c);
    
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "Date";
                    c.HeaderText = "Date";
                    c.Width = 50;
                    t.GridColumnStyles.Add(c);
    
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "728#";
                    c.HeaderText = "728 #";
                    c.Width = 30;
                    t.GridColumnStyles.Add(c);
    
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "Date_Requested";
                    c.HeaderText = "Dt Req'd";
                    c.Width = 50;
                    t.GridColumnStyles.Add(c);
    
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "Requested_By";
                    c.HeaderText = "Req by";
                    c.Width = 70;
                    t.GridColumnStyles.Add(c);
    
                    c = new DataGridTextBoxColumn();
                    c.MappingName = "Note";
                    c.HeaderText = "Note #";
                    c.Width = 200;
                    t.GridColumnStyles.Add(c);
    
                    dgDocs.TableStyles.Add(t);
                }
                myConnection.Close();
            }
       
        }
    }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Datagrid versus Datagridview

    There is plenty of information on how to use the DataGridView in the MSDN library. If you want to know how to use it then that should be your first stop. If you want a particular type of column in a DGV then that's the type of column you add, e,g, if you want a column of combo boxes then you add a DataGridViewComboBoxColumn to the grid. Each column controls its own attributes, rather than having some additional style object.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width