473,399 Members | 2,146 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,399 software developers and data experts.

DataGrid format

I have a datagrid on WinForm and I am trying to format the Grid.
I am using the following code, the code runs fine, but nothing happens after it runs, the datagrid does not change (with data in the grid or with out any data)

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";
DataGrid1.TableStyles.Add(gridStyle);

gridStyle.GridColumnStyles[0].Width = 100;
gridStyle.GridColumnStyles[0].HeaderText="Test Col";
gridStyle.DataGrid.Refresh();
What am I doing wrong?

--
Thanks
-------------------
cz****@wsinc.com
Nov 15 '05 #1
3 2407
I believe you need to create some DataGridColumnStyle objects and add them to the DataGridTableStyle BEFORE you add the DataGridTableStyle to the TableStyles Collection. This is from MSDN documentation:

CAUTION Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle to the collection, DataGridColumnStyle objects are automatically generated for you. Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection. Alternatively, clear the GridColumnStylesCollection using the Clear method.

And when you create the DataGridColumnStyles(normally either DataGridBoolColumn or DataGridTextBoxColumn) make sure you set the MappingName.
Try something like:

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";

DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.MappingName = "Column1";

DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
.....

gridStyle.GridColumnStyles.Add(column);
gridStyle.GridColumnStyles.Add(column2);
.....

DataGrid1.TableStyles.Add(gridStyle);

Good luck,
Jacob
"Peter" <cz****@wsinc.com> wrote in message news:%2******************@tk2msftngp13.phx.gbl...
I have a datagrid on WinForm and I am trying to format the Grid.
I am using the following code, the code runs fine, but nothing happens after it runs, the datagrid does not change (with data in the grid or with out any data)

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";
DataGrid1.TableStyles.Add(gridStyle);

gridStyle.GridColumnStyles[0].Width = 100;
gridStyle.GridColumnStyles[0].HeaderText="Test Col";
gridStyle.DataGrid.Refresh();
What am I doing wrong?

--
Thanks
-------------------
cz****@wsinc.com
Nov 15 '05 #2
Ok, I have the following code and nothing happens after I run it. What do I have to do to format / change the layout of the datagrid?

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";

DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.MappingName = "Column1";

DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
gridStyle.GridColumnStyles.Add(column);
gridStyle.GridColumnStyles.Add(column2);
dataGrid1.TableStyles.Add(gridStyle);

"Jacob" <ja**********@hotmail.com> wrote in message news:VL6Kb.17649$7D3.5362@fed1read02...
I believe you need to create some DataGridColumnStyle objects and add them to the DataGridTableStyle BEFORE you add the DataGridTableStyle to the TableStyles Collection. This is from MSDN documentation:

CAUTION Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle to the collection, DataGridColumnStyle objects are automatically generated for you. Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection. Alternatively, clear the GridColumnStylesCollection using the Clear method.

And when you create the DataGridColumnStyles(normally either DataGridBoolColumn or DataGridTextBoxColumn) make sure you set the MappingName.
Try something like:

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";

DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.MappingName = "Column1";

DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
....

gridStyle.GridColumnStyles.Add(column);
gridStyle.GridColumnStyles.Add(column2);
....

DataGrid1.TableStyles.Add(gridStyle);

Good luck,
Jacob
"Peter" <cz****@wsinc.com> wrote in message news:%2******************@tk2msftngp13.phx.gbl...
I have a datagrid on WinForm and I am trying to format the Grid.
I am using the following code, the code runs fine, but nothing happens after it runs, the datagrid does not change (with data in the grid or with out any data)

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";
DataGrid1.TableStyles.Add(gridStyle);

gridStyle.GridColumnStyles[0].Width = 100;
gridStyle.GridColumnStyles[0].HeaderText="Test Col";
gridStyle.DataGrid.Refresh();
What am I doing wrong?

--
Thanks
-------------------
cz****@wsinc.com
Nov 15 '05 #3
I figured it out. I was not supplying the table name in the DataSet
I was using this code
da.Fill(ds);

instead of

da.Fill(ds, srcTable);
"Peter" <cz****@wsinc.com> wrote in message news:uP**************@TK2MSFTNGP09.phx.gbl...
Ok, I have the following code and nothing happens after I run it. What do I have to do to format / change the layout of the datagrid?

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";

DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.MappingName = "Column1";

DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
gridStyle.GridColumnStyles.Add(column);
gridStyle.GridColumnStyles.Add(column2);
dataGrid1.TableStyles.Add(gridStyle);

"Jacob" <ja**********@hotmail.com> wrote in message news:VL6Kb.17649$7D3.5362@fed1read02...
I believe you need to create some DataGridColumnStyle objects and add them to the DataGridTableStyle BEFORE you add the DataGridTableStyle to the TableStyles Collection. This is from MSDN documentation:

CAUTION Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle to the collection, DataGridColumnStyle objects are automatically generated for you. Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection. Alternatively, clear the GridColumnStylesCollection using the Clear method.

And when you create the DataGridColumnStyles(normally either DataGridBoolColumn or DataGridTextBoxColumn) make sure you set the MappingName.
Try something like:

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";

DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.MappingName = "Column1";

DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
....

gridStyle.GridColumnStyles.Add(column);
gridStyle.GridColumnStyles.Add(column2);
....

DataGrid1.TableStyles.Add(gridStyle);

Good luck,
Jacob
"Peter" <cz****@wsinc.com> wrote in message news:%2******************@tk2msftngp13.phx.gbl...
I have a datagrid on WinForm and I am trying to format the Grid.
I am using the following code, the code runs fine, but nothing happens after it runs, the datagrid does not change (with data in the grid or with out any data)

DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "Test";
DataGrid1.TableStyles.Add(gridStyle);

gridStyle.GridColumnStyles[0].Width = 100;
gridStyle.GridColumnStyles[0].HeaderText="Test Col";
gridStyle.DataGrid.Refresh();
What am I doing wrong?

--
Thanks
-------------------
cz****@wsinc.com
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ron Ford | last post by:
I am trying to reformat data in a data grid column. For simple bound controls, the format and parse methods are available for reformatting database data for display. I can't figure out how to...
2
by: Jim Heavey | last post by:
Hello, I have a datagrid which is bound to a datatable. I created the "DataGridTableStyle" object and defined all of the columns that I wanted to display. There was one column, however that I did...
0
by: Albert Valls Rovira | last post by:
Hello all... I have a DataSet with two DataTables within (for example...) Table 1: Name Surnames CountryID Table 2: id CountryName I have created a relation between both tables (Table...
3
by: NH | last post by:
Hi, Is it possible to format the background of rows (or cells) in a datagrid based on the value of the data in a particular cell. e.g. I have a datagrid of say 21 records, 3 records per day of...
1
by: Ed Bick | last post by:
I am formatting a bound grid. No problem there, does what I expect it to. However, if I click on it a certain number of times, or in a certain sequence, the program crashes. I can't capture the...
6
by: KevinW | last post by:
I need to format a currency column in a datagrid. The line I have tried is: Me.DataGrid1.TableStyles(0).GridColumnStyles(3).ToString.Format("#,##0.00") It does not work. I can format the...
4
by: Barney | last post by:
How can i get my datagrid to read from right to left instead of up and down? I want to be like: BMW Lexus Volvo instead of: BMW Lexus
1
by: aaapaul | last post by:
Hello ! I have a Datagrid with .AutoGenerateColumns = True Colums 1 to X should have the same format. In which event can I set the format ? For i = 0 to dg.columns.count -1...
0
by: ceres80 | last post by:
Hi, I'm developing an application in compact framework .net. I use a DataGrid control and I need a method drawing the grid with the follow properties: 1) No HeaderRows 2) No HeaderCols 3) No...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.