How to Frozen Coumn at Middle of DataGridView columns

Paraman

Member
Joined
Oct 19, 2024
Messages
10
Programming Experience
10+
Hi, Iam using Windows Applications. With my form DataGridView contains 35 columns. When the User Pressed Enter-Key, its focus to next Colum. But my requirement is when the control focused in
15th ColumnIndex I need to Frozen this 15th column, because the user need to refer the 15th Column with 24th Column. And hence is it possible?
I tried by the Following way.
C#:
private void myDataGrid1_CellEnter(object sender, DataGridViewCellEventArgs e){
if (e.ColumnIndex ==15){
myDataGrid1->Columns[15]->Frozen = true;
}
}
private void myDataGrid1_CellLeave(object sender, DataGridViewCellEventArgs e) {
            if (e.RowIndex == 24) {
             myDataGrid1->Columns[15]->Frozen = false;
             }
}

Note :-
My Problem is when the control focused at 15th column, its get frozen at screen last right corner, therefore the 24th column cannot be viewed at screen, so I need to scroll the 15th column as Left Corner and the 24th column also can be displayed...

Any Better Ideas will be helpful !
Thanks
 
Last edited:
I'm assuming that what you are referring to as "frozen" is the Excel concept of freezing columns and rows so that they remain visible in view. As far as I know there is no built in functionality for this in the DataGridView.

It is possible to set the order of the columns, and which columns are visible. It is also possible to set the focus to another cell. There are events fired when a user is done editing a cell, or when the Enter key is pressed. You'll likely need to write your own code to hide and show columns as the user moves left and right through the columns while column 15 is conceptually "frozen". Additionally you'll need to add code for end editing event from a cell in column 15 to set the focus to the corresponf cell in column 24.
 
Maybe combine Frozen with FirstDisplayedScrollingColumnIndex ?
 
Well, I stand corrected regarding the freezing for DataGridView. I was confused how this could have possibly compiled in C#:

myDataGrid1->Columns[15]->Frozen = true;

 
Back
Top Bottom