I have datagridview
in my C# program
and when I move scroll-bar to left, I want that the 2 right columns
will freeze and don't move.
how to do it?
Theres a properties in the columns section of the datagridview to freeze the columns.
Go to your datagridview --> Columns --> (Column you want frozen) --> Frozen = True
EDIT:
After testing it seems that it will only freeze the columns on the left of the datagrid not the right.
EDIT 2:
To get it to freeze the columns on the right enable the "RightToLeft" property on the datagrid. It reverses the order the columns are drawn and allows the rightmost columns to be frozen.
dataGridView1.Columns["columnname"].Frozen = true;
dataGridView1.RightToLeft = Enabled;
You might use one of the DataGridViewElementStates
enumeration values.
Either use an index:
dataGridView1.Columns[0].Frozen = true;
or use the column name:
dataGridView1.Columns["columnName"].Frozen = true;
You may also use the DataGridViewColumnCollection.GetFirstColumn()
method:
dataGridView1.Columns.GetFirstColumn(DataGridViewElementStates.Frozen);
I would personnaly go with the index, since you want the two first columns to freeze. Then, when you want to change these frozen columns, you will only have to change their index in design.
As for making the two columns on the right frozen, I would simply bring them to the right, it is a more ergonomical way to do it, as most of the time, we read from left to right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With