471,075 Members | 1,148 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 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 2324
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ron Ford | last post: by
2 posts views Thread by Jim Heavey | last post: by
reply views Thread by Albert Valls Rovira | last post: by
3 posts views Thread by NH | last post: by
1 post views Thread by Ed Bick | last post: by
6 posts views Thread by KevinW | last post: by
4 posts views Thread by Barney | last post: by
1 post views Thread by aaapaul | last post: by
reply views Thread by leo001 | 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.