Bruno
Bruno

Reputation: 4665

How to refresh DataGridView cells style

I have this simple piece of code on a windows form containing said DataGridView (dgvStatsTable) :

    public void LoadStatsTable(DataTable statsTable)
    {
        dgvStatsTable.DataSource = statsTable;

        var smallFont = new Font(dgvStatsTable.Font.FontFamily, dgvStatsTable.Font.Size * 0.67f);
        dgvStatsTable.Rows[0].Cells[0].Style.Font = smallFont;
        dgvStatsTable.InvalidateCell(0, 0);

        //dgvStatsTable.Invalidate();
        dgvStatsTable.Refresh();
    }

Once that function has been called, my DataGridView contains the correct data to see. However, that style change that I wanted is not showing (first cell in top-right corner has to have smaller text).

Why?

Is it because the table is set to a DataSource rather than building rows and columns?

Thanks!

Upvotes: 2

Views: 9738

Answers (2)

EJC
EJC

Reputation: 2161

The Solution to the problem was to write a handler for the DataGridView.CellFormatting Event

found in this MSDN article in the Setting Styles Dynamically section.

Upvotes: 3

wfoster
wfoster

Reputation: 791

Here is a very nice answer from MSDN network, it appears that in order to have greater control you will need to override some functions.

http://msdn.microsoft.com/en-us/library/7fb61s43(VS.80).aspx

Upvotes: 1

Related Questions