0

I only want 1 row to display in a DataGridView, so I want to somehow hide the checkbox that appears in the column header.

This checkbox is intended to select all the checkboxes, which I don't want to allow users to do.

Image showing the checkbox I want to go away

I'm trying to avoid hiding the column headers and disguising some labels as if they were headers.

Note: I already have the code to uncheck all the other checkboxes when a user clicks on a different one.

Update: I left out that I populated the data from a data source. The "Include" column was not attached to the data source, but added from the data source wizard.

micahhoover
  • 2,101
  • 8
  • 33
  • 53
  • What have you tryed up to now? Maybe with cellformating it could be possible to put a normal header cell over this one – Rémi Jun 20 '13 at 20:08
  • 2
    That's odd, I don't think I've ever seen DGV put a checkbox in the column header.. – Blorgbeard Jun 20 '13 at 20:09
  • 1
    Is this a standard DGV? I just added a checkbox column to one, can't see any way to get this header checkbox to show up.. – Blorgbeard Jun 20 '13 at 20:13
  • @Blorgbeard: This is in VS 2010. It is a standard DGV. – micahhoover Jun 20 '13 at 20:19
  • All kinds of custom DGV should allow you to `Paint` cell content yourself including `Header cell`, so this is not very hard to achieve. – King King Jun 20 '13 at 20:19
  • @im_a_noob: I tried the cellformatting. I couldn't make it go away by setting all the colors to white. I'm not sure what methods I could use to put a normal header cell in either. – micahhoover Jun 20 '13 at 20:22
  • 1
    @micahhoover I don't know how you could show a checkbox on the column header but I created a DataGridView by default and it didn't show any thing on the column header. – King King Jun 20 '13 at 20:22
  • @KingKing: Interesting idea. I guess the user could still click there trigger something I don't want. – micahhoover Jun 20 '13 at 20:22
  • 1
    @micahhoover I'm using VS 2010 also. Framework 3.5 or 4.0? I tried both and didn't see one.. – Blorgbeard Jun 20 '13 at 20:23
  • @KingKing: interesting. Maybe it's some kind of custom rigging the shop I work at has. – micahhoover Jun 20 '13 at 20:23
  • @micahhoover must be custom code somewhere, perhaps something like [this](http://social.msdn.microsoft.com/Forums/windows/en-US/827907ea-c529-4254-9b15-2e6d571f5c5b/adding-a-checkbox-to-a-datagridview-column-header) – Blorgbeard Jun 20 '13 at 20:25

1 Answers1

0

After some advanced experimentation (i.e. fooling around), I learned that naming a field/column "Selected" in the data source will not only cause it to be automatically included in the data grid view as a checkbox, but the header will not have a checkbox and behaves as desired.

enter image description here

Finagling my way to success ...

micahhoover
  • 2,101
  • 8
  • 33
  • 53