Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
Set WinGrid FontFamily at the column level...
posted

I have a grid, DataBound with a DataSet/DataTable, with a number of columns in which I would like to make one column use a font family of "Consolas" because it puts a slash through zeroes. The column in question holds accounts with sometime strange values like A0O7382OU000. As you can see, discerning the zero from the letter O is not so obvious for our users. I went to grid InitializeLayout event and wrote the following expecting the column to format with the font.

grid1.DisplayLayout.Bands[0].Columns["ColumnA"].CellAppearance.FontData.Name = "Consolas";

Sadly this does not work. Then just to test the reality of this I tried the below code to see if I could make ANY change to the cell from this area and found that none of the following lines had any effect on the output of text.

grid1.DisplayLayout.Bands[0].Columns["ColumnA"].CellAppearance.FontData.Bold = DefaultableBoolean.True;
grid1.DisplayLayout.Bands[0].Columns["ColumnA"].CellAppearance.BackColor = Color.Plum;
grid1.DisplayLayout.Bands[0].Columns["ColumnA"].CellAppearance.ForeColor = Color.Red;

None of these had any effect on the grid, but stepping through code I could see I was setting the CellAppearance properties. Obviously, these have nothing to do with the grid's actual display. So where am I going wrong?

Testing, I found that this works, but the font is ugly for anything but a number field. Since it modifies everything in the grid, I cannot use it as a solution. grid1.Font = new Font("Consolas", 9);

So how do you get to the Appearance to change the font family?