HowTo Freeze DataGridView row or column

A

anonieko

You can take a look at the DataGridViewColumn.Frozen property or the
DataGridViewBand class.

Example Code:


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml("XMLFile1.xml");
dataGridView1.DataSource = ds.Tables[0];

FreezeBand(dataGridView1.Rows[0]);
FreezeBand(dataGridView1.Columns[0]);
}

private static void FreezeBand(DataGridViewBand band)
{
band.Frozen = true;
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.BackColor = Color.SkyBlue;
band.DefaultCellStyle = style;
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top