How to set the colour of the row and column header cell borders of a DataGridView?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sheridan
    New Member
    • Oct 2007
    • 9

    How to set the colour of the row and column header cell borders of a DataGridView?

    Hi everyone.

    I'm hoping somone can help me, because I've been stuck on this all evening and haven't found the answer online yet.

    I have a DataGridView control and have managed to change all of the BackColors and GridColors of all of the cells, alternating row cells and selected cels. I have also sucessfully changed the BackColors of the RowHeaders and ColumnHeaders, but I can't for the life of me find out how to change the colour of the borders/gridlines of the RowHeaders and ColumnHeaders.

    Here's what I have so far (just in case anyone is interested):

    dataGridView1.R owsDefaultCellS tyle.SelectionB ackColor = Color.FromArgb( 98, 110, 110);
    dataGridView1.R owHeadersDefaul tCellStyle.Back Color = Color.Black;
    dataGridView1.R owHeadersDefaul tCellStyle.Fore Color = Color.White;
    dataGridView1.C olumnHeadersDef aultCellStyle.B ackColor = Color.Black;
    dataGridView1.C olumnHeadersDef aultCellStyle.F oreColor = Color.White;
    dataGridView1.A lternatingRowsD efaultCellStyle .BackColor = Color.Black;
    dataGridView1.G ridColor = Color.FromArgb( 80, 90, 90);
    dataGridView1.R owsDefaultCellS tyle.BackColor = Color.FromArgb( 27, 30, 30);
    dataGridView1.R owsDefaultCellS tyle.Padding = new Padding(5, 0, 5, 0);
    dataGridView1.R owsDefaultCellS tyle.ForeColor = Color.White;

    I'm hoping someone out there knows. Oh, and one other thing too... I would also like to change the colour of the selected section of the RowHeader, but haven't found a way to do that either. I'll be most grateful for any help in these areas... many thanks (hopefully) in advance.
  • sheridan
    New Member
    • Oct 2007
    • 9

    #2
    Typically, I've just found out how to change the BackColor of the selected RowHeader... strangely enough, it was just:

    dataGridView1.R owHeadersDefaul tCellStyle.Sele ctionBackColor = Color.FromArgb( 98, 110, 110);

    What a surprise! I am still in need of finding out how to change the border/gridline colour of the RowHeaders and ColumnHeaders though, so don't give up on this post yet, please... it's not solved yet! : )

    Comment

    • sheridan
      New Member
      • Oct 2007
      • 9

      #3
      Sorry, I'm a noob! I'm using C# by the way.

      Comment

      • sheridan
        New Member
        • Oct 2007
        • 9

        #4
        No? Oh well, I found out how to sort out the borders now too. Just in case anyone is ever interested, here is how:

        this.dataGridVi ew.RowHeadersBo rderStyle = DataGridViewHea derBorderStyle. Single;
        this.dataGridVi ew.ColumnHeader sBorderStyle = DataGridViewHea derBorderStyle. Single;

        'single' can also be replaced with 'none' if you prefer.

        Comment

        Working...