Prevent scrolling of the first n lines

How to prevent scrolling of the first three rows of scrolling datagridView.

The app is C # windows. Forms with mesh cage 4.5

+3


source to share


2 answers


The property DataGridViewRow.Frozen Property

should work with scrolling using DataGridView

, you only need to set it up in an DataGridView.DataBindingComplete

event: for example:

void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    if (dataGridView1.Rows.Count >= 3)
    {
        dataGridView1.Rows[2].Frozen = true;
    }
}

      

You can set Rows[2]

to freeze as the above lines from this position will freeze as well.

From DataGridViewRow.Frozen property

This property allows one or more rows of important information to be retained as the user scrolls the DataGridView. All lines above the frozen line are also frozen.



Add an event to your grid, for example:

dataGridView1.DataBindingComplete += dataGridView1_DataBindingComplete;

      

and then data binding like:

DataTable dt = GetDataFromDB();
dataGridView1.DataSource = dt;

      

+1


source


See a similar question answered on StackOverflow: Freeze top row and first two columns in datagridview

What you are looking for is the DataGridViewRow.Frozen property. This allows you to freeze any lines you want. (preventing them from scrolling)

You can use it like this:



dataGridView.Rows[0].Frozen = true;

      

This is well documented on MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.frozen%28v=vs.110%29.aspx

If you are having trouble with this, please add some code to your question.

0


source







All Articles