Hi,
[quoted text, click to view] "Sam Carleton" <scarleton@gmail.com> wrote in message
news:1158590224.182973.211800@d34g2000cwd.googlegroups.com...
>I have a datagridview that is bound to a datasource. The under lying
> data is not from a database, but biz objects. The first colume (InUse)
> is a check box to determine if the rest of the row is enabled. When
> the row is not in use, it is grayed out in the CellFormatting event.
> After the user checks the InUse colume, the rest of the row does not
> get repainted.
>
Try CellPainting and get the *editing (or stored)* value then set forecolor
and enable/disable the other cells:
private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if ((e.RowIndex != -1) && (e.ColumnIndex > 0))
{
DataGridViewRow currentRow = dataGridView1.Rows[e.RowIndex];
// returns editing or stored value (from checkboxcell)
bool inUse = (bool)currentRow.Cells[0].EditedFormattedValue;
e.CellStyle.ForeColor = inUse ? Color.Black : Color.Gray;
for (int i = 1; i < dataGridView1.Columns.Count; ++i)
currentRow.Cells[i].ReadOnly = !inUse ;
}
}
Dedect whether the CheckBox is changed during edit and trigger a row
invalidate:
private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
dataGridView1.InvalidateRow(e.RowIndex);
}
private void dataGridView1_CellContentDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
dataGridView1.InvalidateRow(e.RowIndex);
}
private void dataGridView1_CurrentCellDirtyStateChanged(object sender,
EventArgs e)
{
// when user cancel's checkbox edit, dirty state reverts to false
if ( dataGridView1.CurrentCell.ColumnIndex == 0 &&
!dataGridView1.IsCurrentCellDirty )
dataGridView1.InvalidateRow(dataGridView1.CurrentCell.RowIndex);
}
HTH,
Greetings
[quoted text, click to view] > Is there a better way to control editablity of individual rows? If
> not, how do I go about making the whole row get updated correctly? As
> I click on the different cells and leave them, they change to the
> correct color.
>
> Sam
>