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?

Parents
  • 469350
    Offline posted

    Hi,

    The code you have here should work. There are two reasons I can think of why it might not:

    1) Something else in your code is setting, or resetting the CellAppearance on the column after this code is executed. This should be very easy to detect. Simply check the "grid1.DisplayLayout.Bands[0].Columns["ColumnA"].CellAppearance.FontData.Name" at run-time (maybe in a button click) and see if it is still set to what you set it to.

    If it's not, then something overwrote that property. Maybe you are setting this property somewhere else in your code. Maybe you are calling grid.DisplayLayout.Load and the layout you are loading is overwriting it.

    2) If the property IS still set to the correct value and it's still not working, then the only other explanation is that something is overriding it. Maybe you are loading a style library into your application (StyleManager.Load). Or maybe you are applying an appearance to the Cell (which would override the column's more general setting).

Reply Children
No Data