DataGridView White Space After Last Column Header

前端 未结 4 762
时光说笑
时光说笑 2021-02-09 20:28

I\'m trying to mimic what every other tabular view does with the DataGridView control, but I can\'t seem to get the headers correct.

I want a blank header to the right o

4条回答
  •  一整个雨季
    2021-02-09 20:54

    After adding all your columns, you can add an extra column, set the following properties to:

     AutoSizeMode = Fill;
     HeaderText = ""
     ReadOnly = true;
     SortMode = NotSortable;
    

    , handle the gridView CellPainting event for this particular column by preventing the borders from being painted:

     private void dataGridView1_CellPainting(object sender, 
                                             DataGridViewCellPaintingEventArgs e)
     {
         if (e.RowIndex > -1 && e.ColumnIndex == dataGridView1.Columns.Count - 1)
         {
             e.AdvancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
             e.PaintBackground(e.ClipBounds, false);
             e.Handled = true;
         }
     }
    

    and you'll get what you want.

提交回复
热议问题