BindingSource的DataSource是一个具有一些公共属性的类。网格的列是这样创建的:
DataGridViewTextBoxColumn vendorIDColumn =
new DataGridViewTextBoxColumn()
{
MinimumWidth = 50,
FillWeight = 20,
DataPropertyName = "VendorID",
HeaderText = "Vendor ID",
AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
};
grid.Columns.Add(vendorIDColumn);
DataGridView的属性“AutoGenerateColumns”设置为“false”。
尝试grid.Columns[0].DefaultCellStyle.BackColor = Color.Red;
,但没有用。
答案 0 :(得分:0)
您可以设置DataGridViewTextBoxColumn的背景颜色吗?
DataGridViewTextBoxColumn vendorIDColumn =
new DataGridViewTextBoxColumn()
{
MinimumWidth = 50,
FillWeight = 20,
DataPropertyName = "VendorID",
HeaderText = "Vendor ID",
AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
BackColor = Color.Red;
};
grid.Columns.Add(vendorIDColumn);