Articles in this section
Category / Section

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

3 mins read

Freeze the column

Problem

While importing Excel file to WinForms 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

Conclusion

I hope you enjoyed learning about how to freeze the required column after importing the Excel to Grid in WinForms Grid Control.

You can refer to our WinForms Grid Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Grid Control documentation to understand how to present and manipulate data. 

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Grid Control and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied