DareDevil
DareDevil

Reputation: 5349

Removing Line Separator between two cells in DataGridView

I am doing some WinForms work, for DataGridView I have to show blank text for some cells in Grid Header, I want to remove the Line separator to give a user feel like its a single cell.

I will attach a screen-shot for the tentative design, at the moment I did what, Added a panel on to that line, Its fine if I have no re-size-able windows,but when i switch my application to dynamic re-sizing, that shadow panel goes dis-aligned . Kindly suggest any idea how to fix it through coding.
Below is the Image

Upvotes: 3

Views: 2313

Answers (1)

DareDevil
DareDevil

Reputation: 5349

I have sucessfully done this code after code modifications.

The solution is to do all the stuff in _Paint event.

        dataGridView1.EnableHeadersVisualStyles = false;
        Rectangle headerRect = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.Columns["phone"].Index, -1, true); //get the column header cell
        headerRect.X = headerRect.X + headerRect.Width-2;
        headerRect.Y += 1;
        headerRect.Width = 2*2;
        headerRect.Height -= 2;
        DataGridViewColumn dataGridViewColumn = dataGridView1.Columns["<Column>"];
        Color cl; 
        cl = dataGridView1.ColumnHeadersDefaultCellStyle.BackColor;
        e.Graphics.FillRectangle(new SolidBrush(cl), headerRect);

Upvotes: 5

Related Questions