473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 6627
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shivang | last post by:
Hello Everybody, I am using Datagrid control of Winform. I want to have datagrid populated with Unbounded and bounded rows intermittently. I am using tablestyle object as Tablesytle property of...
0
by: zbcong | last post by:
hello in my winform,there is a datagrid,i want to fire some actions when the selected index is changed,but i fail to find the SelectedIndexChanged event to the winform datagrid,why? how can i...
3
by: Dav | last post by:
I have a Winform with a derived datagrid and a button that adds a row to the datagrid in its Click event. The button has a shortcut text "&New Row". When I enter a value in a datagrid cell and...
1
by: Udi | last post by:
Hi everyone! I have a major problem with the DataGrid control for the Windows Form! I am using the DataAdapter to get data from Sql Server 2000 DataBase and populating a DataGrid with the Table i...
1
by: zbcong | last post by:
hello in my winform,there is a datagrid,i want to fire some actions when the selected index is changed,but i fail to find the SelectedIndexChanged event to the winform datagrid,why? how can i...
4
by: Vai2000 | last post by:
Hi All, I have a dataview binded to a datagrid. I do some filter on the view, how can I get the filtered list displayed on the DG in my code The DG is on Winform TIA
8
by: Sunil Menon | last post by:
Dear All, We are developing applications in ASP.Net...in one of our applications we would like to use a GridControl...we have tried to use a Server-Side Grid control but found the speed to be an...
3
by: adh | last post by:
Please refer me to a well developed WinForm Hierarchical DataGrid sample code. I would like to save the cost and troubles of an 3'rd party winforms grid. Thanks, adh
1
by: Jon B | last post by:
Hi All! I would like to make my WinForm DataGrid control so that user could easily edit the items in the **related table**. For instance, I have customers table and it has one-to-many...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.