简体   繁体   中英

Changing The Font Of A DataGrid Cell?

My simple goal is to make the font inside of a particular cell bold. I can't set the Style.Font.Bold property because it is read only, but I can set Style.Font to a new Font object. How do I create a Font object to make it possible to bold the text inside of a particular cell?

grid.Rows[0].Cells[0].Style.Font = new Font(???);

Thanks Stack-O!

If we're talking about WinForms, you can do it like this...

var cell = grid.Rows[0].Cells[0];
cell.Style.Font = new Font(cell.Style.Font, FontStyle.Bold);

If we're talking about a web application, you can do it like this...

grid.Rows[0].Cells[0].Style("font-weight", "bold");

But ideally in a web app this would be handled via CSS with a specific selector...

#GridView1 > tr:first-child > td:first-child {
  font-weight: bold;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM