views:

32

answers:

2

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

    public void LoadStatsTable(StatsTable statsTable)
    {
        dgvStatsTable.DataSource = statsTable.GetTable();  // returns a DataTable

        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!

A: 

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

wfoster
+1  A: 

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.

EJC