DataGridView DataBinding to a columns Enabled property

DataGridView DataBinding to a columns Enabled property

Old forum URL: forums.lhotka.net/forums/t/300.aspx


pfeds posted on Wednesday, June 07, 2006

There is probably a simple solution to this, so excuse me if I'm being a bit dumb... Stick out tongue [:P]

I have a DataGridView bound to a collection. It displays a text column and a checkbox column.  This binds to a string and bool property on my object. Simple stuff.

The problem is I have another boolean property that defines whether the checkbox should be displayed.  What I need to do is display the check box if this property is set to true, and hide it if false, on a row by row basis.

Any ideas? Thanks.

ajj3085 replied on Wednesday, June 07, 2006

I don't think you can't pick and choose cells to display; entire columns, yes, but not cells.  You'd have to enable disable the cell for the row based on your other boolean property.

HTH
Andy

Mark replied on Wednesday, June 07, 2006

DataGridView has so many events - there's probably a way to do this (might involve owner-drawn cells).  I've used the CellFormatting event in the past to customize how field values are displayed.  Either this event or the CellPaiting event might be of use.  If you can't find the solution, you might check out the MSDN forums as well.

pfeds replied on Thursday, June 08, 2006

After all that, it now turns out I don't need to do what I said Confused [*-)]

I did come up with a couple of solutions, but neither were ideal.  The first was to make the column read only, and use a context menu to modify the value.  In that way I could check on the popup event whether the given row can have the boolean value edited.

The other way is similar by using the context menu (or a button etc).  If I make the value a nullable bool and make the column a text column then I will either get "True", "False", or "".  Still, a bit untidy though. 

Maybe a solution would be to create a new DataGridView Column type...

Copyright (c) Marimer LLC