471,350 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Create new winform datagrid

Everyone:

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();

CHGrid.DataSource = DFLTable;

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

// 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.
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.MappingName = "DefectFoundLocationId";
myDataCol.HeaderText = "My New Column";
myDataCol.Width = 100;
ts1.GridColumnStyles.Add(myDataCol);

CHGrid.TableStyles.Add(ts1);

The DFL.LoadAll() just gets all the data from a table. My grid is
populated with the 4 columns being returned from DFL.LoadAll() but the
column I create is not being displayed.

I want to display only the column(s) I create and not have the grid
auto-populate.

Thanks for the help,
Dale Williams
Dec 19 '05 #1
1 6547
Hi Dale,

Define all the column and table styles FIRST and bind the grid to the data
source SECOND (I'd also recommend that you do the binding with the grid's
SetDataBinding method.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Dale Williams" <dw*******@yf.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Everyone:

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();

CHGrid.DataSource = DFLTable;

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

// 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.
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.MappingName = "DefectFoundLocationId";
myDataCol.HeaderText = "My New Column";
myDataCol.Width = 100;
ts1.GridColumnStyles.Add(myDataCol);

CHGrid.TableStyles.Add(ts1);

The DFL.LoadAll() just gets all the data from a table. My grid is
populated with the 4 columns being returned from DFL.LoadAll() but the
column I create is not being displayed.

I want to display only the column(s) I create and not have the grid
auto-populate.

Thanks for the help,
Dale Williams


Dec 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Udi | last post: by
4 posts views Thread by Vai2000 | last post: by
8 posts views Thread by Sunil Menon | last post: by
3 posts views Thread by adh | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.