110,502
社区成员
发帖
与我相关
我的任务
分享
private void Form2_Load(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection("server=(local);database=Northwind;user id=sa;password=sa;"))
{
using (SqlDataAdapter adapter = new SqlDataAdapter("Select * FROM Products", conn))
{
DataTable table = new DataTable();
adapter.Fill(table);
dataGridView1.DataSource = table;
}
}
//设置第一行高度、背景色
dataGridView1.Rows[0].Height = 100;
dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Red;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(dataGridView1.Rows[0].Height.ToString() + "\r\n" + dataGridView1.Rows[0].DefaultCellStyle.BackColor.ToString());
/*
* 结果:
*
* 23
* Color[Empty]
*/
}
private void button1_Click(object sender, EventArgs e)
{
//设置第一行高度、背景色
dataGridView1.Rows[0].Height = 100;
dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Red;
MessageBox.Show(dataGridView1.Rows[0].Height.ToString() + "\r\n" + dataGridView1.Rows[0].DefaultCellStyle.BackColor.ToString());
/*
* 结果:
*
* 100
* Color[Red]
*/
}