Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get a multiline head using DataGridView?

How to get a multiline head using DataGridView?

Scheduled Pinned Locked Moved C#
tutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xzl1234
    wrote on last edited by
    #1

    I want to have a GridView like this. But it seems DataGridView only support one line head, is there anyway to do this? By the way, I have tried NetVantage. But I think it's a little bit slow when loading controls, so I'm wondering if I can just using DataGridView to do this? :) Personal Info Contact Info Name Age Gender Mobile Phone Email Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data

    X A 2 Replies Last reply
    0
    • X xzl1234

      I want to have a GridView like this. But it seems DataGridView only support one line head, is there anyway to do this? By the way, I have tried NetVantage. But I think it's a little bit slow when loading controls, so I'm wondering if I can just using DataGridView to do this? :) Personal Info Contact Info Name Age Gender Mobile Phone Email Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      DataGridView doesnt supports multiple headers for a column, however you can separate the text of header by this ( | ) that will look like a line multiple headers

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      X 1 Reply Last reply
      0
      • X Xmen Real

        DataGridView doesnt supports multiple headers for a column, however you can separate the text of header by this ( | ) that will look like a line multiple headers

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        X Offline
        X Offline
        xzl1234
        wrote on last edited by
        #3

        The method you say can't slove my problem. I want the head can be change the width, so if I use the "|" to instead of column, it won't work.

        X 1 Reply Last reply
        0
        • X xzl1234

          The method you say can't slove my problem. I want the head can be change the width, so if I use the "|" to instead of column, it won't work.

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #4

          so why dont you use columns, they will work as you want

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          X 1 Reply Last reply
          0
          • X xzl1234

            I want to have a GridView like this. But it seems DataGridView only support one line head, is there anyway to do this? By the way, I have tried NetVantage. But I think it's a little bit slow when loading controls, so I'm wondering if I can just using DataGridView to do this? :) Personal Info Contact Info Name Age Gender Mobile Phone Email Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data

            A Offline
            A Offline
            Anoop Unnikrishnan
            wrote on last edited by
            #5

            Drag and drop a GridView and name it as GridView1 Try the below code protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable("Employee"); //Name Age Gender Mobile Phone Email dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Columns.Add("Gender"); dt.Columns.Add("Mobile"); dt.Columns.Add("Phone"); dt.Columns.Add("Email"); dt.Rows.Add("Anoop", "25", "Male", "996633352", "02255566", "anoopukrish@gmail.com"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { GridView gridView = (GridView)sender; GridViewRow gridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert); TableCell tableCell = new TableCell(); //add Personal Info tableCell.Text = "Personal Info"; tableCell.Attributes.Add("style", "text-align: center"); tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); //Add Contact Info tableCell = new TableCell(); tableCell.Attributes.Add("style", "text-align: center"); tableCell.Text = "Contact Info"; tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); GridView1.Controls[0].Controls.AddAt(0, gridViewRow); } } ... There by u get the desired output... :-\ ____________________:cool: Anoop Unnikrishnan

            X 1 Reply Last reply
            0
            • A Anoop Unnikrishnan

              Drag and drop a GridView and name it as GridView1 Try the below code protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable("Employee"); //Name Age Gender Mobile Phone Email dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Columns.Add("Gender"); dt.Columns.Add("Mobile"); dt.Columns.Add("Phone"); dt.Columns.Add("Email"); dt.Rows.Add("Anoop", "25", "Male", "996633352", "02255566", "anoopukrish@gmail.com"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { GridView gridView = (GridView)sender; GridViewRow gridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert); TableCell tableCell = new TableCell(); //add Personal Info tableCell.Text = "Personal Info"; tableCell.Attributes.Add("style", "text-align: center"); tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); //Add Contact Info tableCell = new TableCell(); tableCell.Attributes.Add("style", "text-align: center"); tableCell.Text = "Contact Info"; tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); GridView1.Controls[0].Controls.AddAt(0, gridViewRow); } } ... There by u get the desired output... :-\ ____________________:cool: Anoop Unnikrishnan

              X Offline
              X Offline
              xzl1234
              wrote on last edited by
              #6

              Your code is for webpage gridView control, it doesn't work for winform GridView Control. Thank you for the codes, are you still have some codes for winform GridView Control?

              1 Reply Last reply
              0
              • X Xmen Real

                so why dont you use columns, they will work as you want

                TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                X Offline
                X Offline
                xzl1234
                wrote on last edited by
                #7

                It's seems you didn't get what I have said. I want a grid like this, but not so complex. I just want the head part is the same as showing in the picture. http://p.blog.csdn.net/images/p_blog_csdn_net/venus0314/2d96ca3709e3450ea3a91d9bf909021f.png[^]

                X 1 Reply Last reply
                0
                • X xzl1234

                  It's seems you didn't get what I have said. I want a grid like this, but not so complex. I just want the head part is the same as showing in the picture. http://p.blog.csdn.net/images/p_blog_csdn_net/venus0314/2d96ca3709e3450ea3a91d9bf909021f.png[^]

                  X Offline
                  X Offline
                  Xmen Real
                  wrote on last edited by
                  #8

                  then use third party controls

                  TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups