🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #274

Creating a winform datagrid

#274
From: Dale Williams
Date: Mon, 19 Dec 2005 20:35
39 lines
2140 bytes
     Using C#, I'm trying to create a datagrid on a winform 
programatically.  I placed the datagrid and the form and named it 
CHGrid.  Here's the code I'm using:

	// Get and bind the data.
	QarBusTier.DefectFoundLocation DFL = new QarBusTier.DefectFoundLocation();
	System.Data.DataTable DFLTable = DFL.LoadAll();

	// Set the data grid style.
	DataGridTableStyle ts1 = new DataGridTableStyle();
	ts1.MappingName = "DFLTable";

	// Set the datagrid style.
	CHGrid.Top   = 50;
         CHGrid.Left  = 200;
	CHGrid.Width = 350;
	CHGrid.Height= 200;
	CHGrid.ForeColor = System.Drawing.Color.Black;
	CHGrid.BackColor = System.Drawing.Color.Beige;

	// Create column.
	DataGridColumnStyle myDataCol = new DataGridTextBoxColumn();
	myDataCol.MappingName = "DefectFoundLocationId";
	myDataCol.HeaderText = "My New Column";
	myDataCol.Width = 20;
	ts1.GridColumnStyles.Add(myDataCol);

	CHGrid.TableStyles.Add(ts1);

	The column never appears on the datagrid.  If I add the following line, 
I'll get the columns from the table but not the column I've created.
	CHGrid.DataSource = DFLTable;

	I don't want any default columns to appear, only the columns I create.

	Thanks for the help,
Dale Williams

	
Technical Details
Message-ID: <43a7191b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,416c2fe69f593b28,start
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 19 Dec 2005 15:35:00 -0500
From: Dale Williams <dwilliams@yf.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.11) Gecko/20050728
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.csharpbuilder.language.csharp
Subject: Creating a winform datagrid
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 72.43.20.144
Message-ID: <43a7191b@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1135024411 72.43.20.144 (19 Dec 2005 12:33:31 -0700)
Lines: 40
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail