Advertisement
7_2009-2012 String Manipulation #228258

Hide & Disable Columns in DataGrid

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.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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")
Upload
Original Comments (3)
Recovered from Wayback Machine