Skip to main content


Showing posts from March, 2005

Visual Studio Team System Site

Visual Studio Team System Site
Version Control Blogs
Work Item Tracking Blogs

How to Read Hierarchical Data into a DataSet (via .NET 247)

This example uses the Customers and Orders tables that are included with the Microsoft SQL Server sample Northwind database:
1. Create a new Visual C# Console Application project. Class1.cs is created by default.
2. If the Code window is not open, right-click Class1.cs in Solution Explorer, and then click View Code.
3. Delete all of the code from the Code window.
4. Paste the following code into the Code window:

using System;
using System.Data;
using System.Data.OleDb;

namespace CSharpSample
/// Summary description for Class1
class Class1
/// The main entry point for the application
static void Main(string[] args)
// TODO: Add code to start application here
OleDbConnection nwindConn = new OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=l…

5.35 How do I set the width of a column in my DataGrid?

Windows Forms FAQ - Windows Forms Datagrid: "5.35 How do I set the width of a column in my DataGrid?

To set a column width, your datagrid must be using a non-null DataGridTableStyle. Once this is in place, you can set the column width by first getting the tablestyle and then using that object to obtain a column style with which you can set the width. Here are some code snippets showing how you might do this.
//.... make sure your DataGrid is using a tablestyle
dataGrid1.DataSource = _dataSet.Tables['customers'];
DataGridTableStyle dgts = new DataGridTableStyle();
dgts.MappingName = 'customers';


//method to set a column with by colnumber
public void SetColWidth(DataGridTableStyle tableStyle, int colNum, int width)
tableStyle.GridColumnStyles[colNum].Width = width;
catch{} //empty catch .. do nothing


// here is how you might call this m…

Secure ASP.NET sites from XSS

Use the following module:

If you think you can just hard code a few chars to prevent it, try