Set display text of a cell

0
0

I have a database column of type int that represent the gender (Company=0, Male=1, Female=2)

I want to display that column in a DGV column but I don’t want to see the numbers from the database, I want to display “Company”, “Mr.”, “Mrs”. How can I do that?

  • You must to post comments
0
0
  • Henry Fechtmann
    Thank you for your advice. In the meantime I found an easier and obvious way by just extending the database entity class with a non-mapped property that returns the display value. That works very well. Nevertheless your hint was very useful because it answered another question I had: how to apply a bold font to rows depending on a cell value? I used the cell formatting event like this: bool IsAdmin = (bool)UserGrid.GetValue(ColumnIsAdmin.Index, e.RowIndex); if (IsAdmin) e.CellStyle.Font = new Font(UserGrid.Font, FontStyle.Bold); Happy New Year
  • Luca (ITG)
    Sounds good and happy new year! Instead of creating a new font on each formatting call you can create a bold instance and reuse it. You can also use new Font(“@defaultBold”) to use the bold font defined in the theme. Or new Font(“defaultBold”, ….) if you want to change the size or style. When using “@“ it uses a theme font as is. Without the “@“ it uses the theme font but it can change it. Another good approach is to create static DataGridViewCell objects and reuse those by assigning them to either cells, rows or columns. Saves a lot of memory and make it very flexible.
  • Henry Fechtmann
    Thanks for the hints! All New Year parties are cancelled and I’m stuck at home so I play a bit. Wisej seems to be the best solution by far when you want to write a business application for the browser. It’s the same as programming WinForms, everything looks so familiar and you can get things done so fast. And the support seems to work fine as well (I’m sure I will have more questions down the road :-) Some time next year I’ll start development of a new inhouse app and I’m already pretty sure I’ll use Wisej.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.