C#Winforms DataGridView粗体字体行样式
为什么行中没有文本? 如何使行中的文本加粗C#Winforms DataGridView粗体字体行样式,c#,winforms,datagridview,C#,Winforms,Datagridview,为什么行中没有文本? 如何使行中的文本加粗 namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.dataGridView1.AutoGenerateColumns = false; this.da
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.Columns.Add(new DataGridViewColumn { HeaderText = "Test", CellTemplate = new DataGridViewTextBoxCell() { }, DefaultCellStyle = new DataGridViewCellStyle { Font = new Font("Tahoma", 9.75F, FontStyle.Bold) } });
this.dataGridView1.DataSource = new List<Employee>
{
new Employee {Name="Test"},
new Employee {Name="Test"},
new Employee {Name="Test"},
new Employee {Name="Test"},
new Employee {Name="Test"},
new Employee {Name="Test"},
new Employee {Name="Test"}
};
}
}
public class Employee
{
public string Name { get; set; }
public int Number { get; set; }
}
}
命名空间窗口窗体应用程序1
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
this.dataGridView1.AutoGenerateColumns=false;
this.dataGridView1.Columns.Add(newdatagridviewcolumn{HeaderText=“Test”,CellTemplate=newdatagridviewtextboxcell(){},DefaultCellStyle=newdatagridviewcellstyle{Font=newfont(“Tahoma”,9.75F,FontStyle.Bold)});
this.dataGridView1.DataSource=新列表
{
新员工{Name=“Test”},
新员工{Name=“Test”},
新员工{Name=“Test”},
新员工{Name=“Test”},
新员工{Name=“Test”},
新员工{Name=“Test”},
新员工{Name=“Test”}
};
}
}
公营雇员
{
公共字符串名称{get;set;}
公共整数{get;set;}
}
}
您缺少列的属性
获取或设置DataGridViewColumn绑定到的数据源属性或数据库列的名称
将其更改为:
this.dataGridView1.Columns.Add(new DataGridViewColumn {
HeaderText = "Test",
DataPropertyName = "Name",
CellTemplate = new DataGridViewTextBoxCell() { },
DefaultCellStyle = new DataGridViewCellStyle { Font = new Font("Tahoma", 9.75F, FontStyle.Bold), ForeColor = Color.Black }
});
这将添加粗体字体的行。public Form1()
public Form1()
{
InitializeComponent();
BindingList<Employee> list = new BindingList<Employee>();
list.Add(new Employee() { Name = "Test1" });
list.Add(new Employee() { Name = "Test2" });
list.Add(new Employee() { Name = "Test3" });
list.Add(new Employee() { Name = "Test4" });
list.Add(new Employee() { Name = "Test5" });
dataGridView1.DataSource = list;
}
{
初始化组件();
BindingList=新建BindingList();
添加(新员工(){Name=“Test1”});
添加(新员工(){Name=“Test2”});
添加(新员工(){Name=“Test3”});
添加(新员工(){Name=“Test4”});
添加(新员工(){Name=“Test5”});
dataGridView1.DataSource=列表;
}