views:

49

answers:

2

I have a DataGridView which is filling from Table in SQL Server Database. One of it's columns is "price".

Type of column in DGV is automatically sets as Decimal.

In some cases I need to write in cells of this column text like "none", instead of price.

How can I do it?

DGV.Item("price", 0).Value = "none" doesn't work, because of decimal type of a cell.

A: 

Look at implementing IFormatProvider & ICustomFormatter...

Then in DGV you can assign it to the column format via ColumnFormatProvider.

ozczecho
A: 

If you just want to change how the data is displayed (and that's what it sounds like you want), hook the CellFormatting event. Here's the general idea (code untested):

private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (some_condition(e.ColumnIndex, e.RowIndex)) {
        e.Value = "none";
        e.FormattingApplied = true;
    }
}
Daniel Stutzbach