Hi,
I can't seem to make a disabled checkbox in a datagridview with a tick in where the user can't select & stores a value of 0
I got this off the net but it shows a disabled box with no tick in and no value sored in the background as well even more dissapointing
once the mouseover or mousemove between rows the so called disabled checkbox chnages to enable or state.
On the CellPainting Event:
e.PaintBackground(e.CellBounds, true);
Rectangle r = e.CellBounds;
r.Width = 15;
r.Height = 15;
r.X += e.CellBounds.Width / 2 - 8;
r.Y += e.CellBounds.Height / 2 - 8;
ControlPaint.DrawCheckBox(e.Graphics, r, ButtonState.Flat);
e.Handled = true;
Is there no other way?
Please Assist, Regards
Loading

Nir Bar107 reputationPosted Sep 30, 2009, 5:03 AM EDT
There isn't a built-in way. However you can set it's color to grey
dataGridView1.CurrentCell.Style.BackColor = Color.Grey;
Regarding the count - just loop over the rows, and count only those that aren't ReadOnly
Please mark this post as an answer if it helps you
Nir
Nir Bar107 reputationPosted Sep 30, 2009, 3:37 AM EDT
I'm not sure I got you right:
Do you want the checkbox to be unchecked, and disable changes by the user?
If so, then set FalseValue to 0, Value to 0, and ReadOnly to true (similar properties exist in the column as well, which will apply for all the cells in the column)
If you mean something else, then please clarify
Please mark this post as an answer if it helps you
Nir
ic ic80 reputationPosted Sep 30, 2009, 4:13 AM EDT
dgvDetail.CurrentRow.Cells[10].Value = 1;
dgvDetail.CurrentRow.Cells[10].ReadOnly = true;
Is there a way of making it disabled?
As well as at the end I roll through table to check for checkbox having a 1 value, how would i exclude the ones i set to readonly from the check?
Please Assis!
ic ic80 reputationPosted Sep 30, 2009, 5:49 AM EDT
I would have like to have the checkbox looked disabled!
Nir Bar107 reputationPosted Sep 30, 2009, 6:09 AM EDT
Didn't it do the trick?
Nir
ic ic80 reputationPosted Sep 30, 2009, 6:21 AM EDT
The problem is that when the user activates more checkboxes with backcolor also changing the readonly ones does not stand out visually.
Regards
Nir Bar107 reputationPosted Sep 30, 2009, 6:29 AM EDT
So why not change the back-color of the read-only cells to a different one?
ic ic80 reputationPosted Sep 30, 2009, 9:51 PM EDT