README.md

December 4, 2022 ยท View on GitHub

Hide & Disable Columns in DataGrid

Description

This few lines of Code demonstrate how to Hide & Disable(lock) columns in Datagrid. Taking example from Northwind database it allows user to modify only ContactName,Phone and Fax columns.

Add this code in Form load event and modify the Connection string if required.

also add Imports System.Data.SqlClient in your code.

hope it helps you.

More Info

Submitted On
BySyed
LevelBeginner
User Rating4.2 (25 globes from 6 users)
CompatibilityVB.NET
CategoryDatabases
World.Net (C#, VB.net)
Archive File

Source Code

Dim CN As New SqlConnection("server=(local);Database=Northwind;User ID=sa;password=;")
 CN.Open()
 Dim DA As New SqlDataAdapter("Select CustomerID, CompanyName, ContactName, Phone, Fax from Customers order by 1", CN)
 Dim DS As New DataSet()
 'DA.FillSchema(DS, SchemaType.Source, "Cust")
 DA.Fill(DS, "Cust")
 DS.Tables("Cust").Columns("CustomerID").ColumnMapping = MappingType.Hidden
 DS.Tables("Cust").Columns("CompanyName").ReadOnly = True
 DataGrid1.SetDataBinding(DS, "Cust")