473,394 Members | 1,189 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,394 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 6629
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.