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. DataGrid Column Header

DataGrid Column Header

Scheduled Pinned Locked Moved C#
csharpquestionannouncement
7 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.
  • S Offline
    S Offline
    Small Rat
    wrote on last edited by
    #1

    Hi all, is there any way to customize the looking of the column header of datagrid?? Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

    R N 2 Replies Last reply
    0
    • S Small Rat

      Hi all, is there any way to customize the looking of the column header of datagrid?? Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      No easy way. Overriding OnPaint (or catching the Paint event) and drawing over the existing ones is the only way.

      S 1 Reply Last reply
      0
      • R Robert Rohde

        No easy way. Overriding OnPaint (or catching the Paint event) and drawing over the existing ones is the only way.

        S Offline
        S Offline
        Small Rat
        wrote on last edited by
        #3

        How do I know if the current cell is the header cell when I override the paint method? thanks!! Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

        R 1 Reply Last reply
        0
        • S Small Rat

          How do I know if the current cell is the header cell when I override the paint method? thanks!! Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          As said not trivial. The grid has a GetCellBounds function which you can use to determine the bounds of a cell. The problem is that this doesn't include header cells. But if you have the bounds of the cells in the first row you should be able to calculate where the header 'should' be. If you have this you will have to repaint every header cell everytime Paint is called.

          1 Reply Last reply
          0
          • S Small Rat

            Hi all, is there any way to customize the looking of the column header of datagrid?? Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

            N Offline
            N Offline
            Nader Elshehabi
            wrote on last edited by
            #5

            I don't think I get it!! If you are asking about customizing the column header at design time, just look at the properties window. Look for a property named "ColumnHeaderDefaultCellStyle". There you can change the color, font, formatting, and anything else you want in the Column headers appearance at design time. There are also some other properties in the properties window that you can change (eg. BorderRaised property). If your question was about changing the look of a certain column header at run time, you can use either use "DataGridView1.Columns[X].HeaderCell" (where X is the column number), to access the header cell directly, or one of the followings: DataGridView1.ColumnHeadersBorderStyle; DataGridView1.ColumnHeadersDefaultCellStyle; to change the border style and the cell style respectively at run time. I hope that solves it. If it doesn't, post me more details of what you need, maybe I can help.

            S 1 Reply Last reply
            0
            • N Nader Elshehabi

              I don't think I get it!! If you are asking about customizing the column header at design time, just look at the properties window. Look for a property named "ColumnHeaderDefaultCellStyle". There you can change the color, font, formatting, and anything else you want in the Column headers appearance at design time. There are also some other properties in the properties window that you can change (eg. BorderRaised property). If your question was about changing the look of a certain column header at run time, you can use either use "DataGridView1.Columns[X].HeaderCell" (where X is the column number), to access the header cell directly, or one of the followings: DataGridView1.ColumnHeadersBorderStyle; DataGridView1.ColumnHeadersDefaultCellStyle; to change the border style and the cell style respectively at run time. I hope that solves it. If it doesn't, post me more details of what you need, maybe I can help.

              S Offline
              S Offline
              Small Rat
              wrote on last edited by
              #6

              hi, actually I am using the DataGrid control (not DataGridView) from the vs2005. I know is not recommanded. but for some history reason I have to use it. also I bind the grid to a arraylist. I want show the triangle icon when I sor the selected column. I just want to simple sort the arraylist and use refresh to update the binding. it works, but I can not see the little triangle. do you have any idea about this??? Thanks a lot! Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

              N 1 Reply Last reply
              0
              • S Small Rat

                hi, actually I am using the DataGrid control (not DataGridView) from the vs2005. I know is not recommanded. but for some history reason I have to use it. also I bind the grid to a arraylist. I want show the triangle icon when I sor the selected column. I just want to simple sort the arraylist and use refresh to update the binding. it works, but I can not see the little triangle. do you have any idea about this??? Thanks a lot! Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!

                N Offline
                N Offline
                Nader Elshehabi
                wrote on last edited by
                #7

                Well, now I can see your problem. I'm not sure this will be easy but I think if you have to override th OnPaint event you can put an if statement at the begining to check for the CurrentCell or RowIndex properties to make sure that you are in the header row, but I don't know how that be of any help. Another way I can think of doing this is by putting a + or - in the header cell's text;P, I know it's silly but I can't think of anything else right now!! I even tried to use the ascii code to put the triangle (Codded 1E for up & 1F for down) in the text but it doesn't work! while I was digging up I also found "dataGrid1.TableStyles[0].GridColumnStyles[x]" property!! maybe it will be of some assistance. You may also get the ClientRectangle, or the Displayrectangle of the DataGrid. Then add the widthes of the columns before the selected column to 0 and this will be the location of your column. Then use the System.Drawing to draw your rectangle in the header's area. But what's worth all this effort?!! -- modified at 17:46 Tuesday 16th May, 2006

                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