Datagridview image column nulls

E

Earl

I've got a datagridview bound to Sql2k database. When the image columns
return null, I get the goofy looking [X] in the column instead of a blank.
Anyone know how to make that just appear as empty instead of the default
[X]? I would also like that to appear as empty when I insert a new row
instead of the [X] if that is possible.
 
B

Bart Mermuys

Hi,

Earl said:
I've got a datagridview bound to Sql2k database. When the image columns
return null, I get the goofy looking [X] in the column instead of a blank.
Anyone know how to make that just appear as empty instead of the default
[X]?

You can set "someColumn.DefaultCellStyle.NullValue = null;".
I would also like that to appear as empty when I insert a new row instead
of the [X] if that is possible.

If you want this too, then *instead* you can handle the cell paint event:

private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
// suppose 2nd column is a image column
if ((e.ColumnIndex == 1) && (e.FormattedValue == e.CellStyle.NullValue))
{
DataGridViewPaintParts pp = e.PaintParts &
~DataGridViewPaintParts.ContentForeground;
e.Paint(e.ClipBounds, pp);
e.Handled = true;
}
}

HTH,
Greeting
 
E

Earl

Thanks Bart, that helped.

Bart Mermuys said:
Hi,

Earl said:
I've got a datagridview bound to Sql2k database. When the image columns
return null, I get the goofy looking [X] in the column instead of a
blank. Anyone know how to make that just appear as empty instead of the
default [X]?

You can set "someColumn.DefaultCellStyle.NullValue = null;".
I would also like that to appear as empty when I insert a new row instead
of the [X] if that is possible.

If you want this too, then *instead* you can handle the cell paint event:

private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
// suppose 2nd column is a image column
if ((e.ColumnIndex == 1) && (e.FormattedValue == e.CellStyle.NullValue))
{
DataGridViewPaintParts pp = e.PaintParts &
~DataGridViewPaintParts.ContentForeground;
e.Paint(e.ClipBounds, pp);
e.Handled = true;
}
}

HTH,
Greeting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top