)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to freeze the required column after importing the Excel to Grid in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: February 9, 2015 |
Last Revised Date: December 16, 2019

Freeze the column

Problem

While importing Excel file to Grid, the Grid imports only the data and not the freeze panes.

Solution

You can freeze the required column after importing the Excel file to the Grid by using FrozenCount property. Using this property, you can set the worksheet as VerticalSplit to display the freeze pane on the required column.

C#

// To import excel file
String xlpath = Application.StartupPath + "\\book1.xlsx";
if (!File.Exists(xlpath)) {
MessageBox.Show(xlpath + " not found, please update the path");
return;
}
try {
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook myWorkbook = null;
myWorkbook = excelEngine.Excel.Workbooks.Open(xlpath, ExcelOpenType.Automatic);
GridExcelConverterControl gecc = new GridExcelConverterControl();
IWorksheet mySheet = myWorkbook.Worksheets[0];
gecc.ExcelToGrid(mySheet, gridControl1.Model);
// To freeze the required column
this.gridControl1.Cols.FrozenCount = mySheet.VerticalSplit;
} catch (Exception ex) {
MessageBox.Show(ex.Message, "Grid - LoadFromExcelFile error");

VB

' To import excel file
Dim xlpath As String = Application.StartupPath & "\\book1.xlsx"
If Not File.Exists(xlpath) Then
MessageBox.Show(xlpath & " not found, please update the path")
Return
End If
Try
Dim excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
Dim myWorkbook As IWorkbook = Nothing
myWorkbook = excelEngine.Excel.Workbooks.Open(xlpath, ExcelOpenType.Automatic)
Dim gecc As New GridExcelConverterControl()
Dim mySheet As IWorksheet = myWorkbook.Worksheets(0)
gecc.ExcelToGrid(mySheet, gridControl1.Model)
' To freeze the required column
Me.gridControl1.Cols.FrozenCount = mySheet.VerticalSplit
Catch ex As Exception
MessageBox.Show(ex.Message, "Grid - LoadFromExcelFile error")
End Try

Samples:

C#: Freeze column CS

VB: Freeze column VB

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon