Home > Net >  C # to DataGridView column DefaultCellStyle custom code
C # to DataGridView column DefaultCellStyle custom code

Time:04-16

Doing DGV, give a code format,

Now I would like to give a single column to change the font, directly added in the add
DGV. Columns. Add (
New DataGridViewTextBoxColumn
{
ReadOnly=true,
The Visible=true,
The HeaderText="status",
Name="Status",
DataPropertyName="Status",
AutoSizeMode=DataGridViewAutoSizeColumnMode ColumnHeader,
DefaultCellStyle=??????
}
);

In VS UI interface Settings, have defaultCellstyle, there is a large set of places,
But in the designer. Can't find in the cs,

Is this copy out of the interface,
DataGridViewCellStyle {BackColor=Color [ButtonHighlight], ForeColor=Color [ControlText], the Font=[Font: Name=Microsoft black, Size=12, Units=3, GdiCharSet=134, GdiVerticalFont=False], the Format=g, Alignment=MiddleCenter}

How am I supposed to write in the new code? Then have DefaultCellStyle, but behind how to write, I don't know, hope comment

CodePudding user response:

Can handle a column inside the formatting function style
Such as
Enclosing dgvResult. Rows [" e.R owIndex] Cells [r]. "ResultAbnormal" style.css. BackColor=Color. FromArgb (251, 202, 210);

CodePudding user response:

DataGridView1. Columns [0]. DefaultCellStyle. ForeColor=Color. Red;
DataGridView1. Columns [0]. DefaultCellStyle. The Font=new Font (" tahoma ", 10);
DataGridView1. Columns [1]. DefaultCellStyle. ForeColor=Color. Black;
DataGridView1. Columns [1]. DefaultCellStyle. The Font=new Font (" tahoma ", 20);

CodePudding user response:

This I know, I just want to add, the new set up directly, how do you write the code?
  •  Tags:  
  • C#
  • Related