VB icon

Hide & Disable Columns in DataGrid

Email
Submitted on: 1/1/2015 10:24:00 AM
By: Syed (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB.NET
Views: 867
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: 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.
// By: Syed (from psc cd)
//**************************************

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")


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.