Groups | Blog | Home
all groups > dotnet windows forms databinding > july 2004 >

dotnet windows forms databinding : How to change GridColumnStyle of DataGrid control ?


Larry
7/26/2004 11:02:41 AM
Hi my friends,

I'm using a DataGrid Control to display a DataTable from Dataset. I can
display it in default format. I want to adjust the width of each column. I
went to properties of DataGrid control and set TableStyles and added
gridcolumnstyles in GridColumnStyles collection. But it doesn't work. Why.

I also tried to following code:
DataGridTableStyle tbstyle=new DataGridTableStyle();

DataGridTextBoxColumn paidtostyle=new DataGridTextBoxColumn();

paidtostyle.Width=400;

DataGridTextBoxColumn amountstyle=new DataGridTextBoxColumn();

amountstyle.Width=150;

DataGridTextBoxColumn paiddatestyle=new DataGridTextBoxColumn();

paiddatestyle.Width=100;

DataGridTextBoxColumn memostyle=new DataGridTextBoxColumn();

memostyle.Width=100;


tbstyle.GridColumnStyles.Add(paidtostyle);

tbstyle.GridColumnStyles.Add(amountstyle);

tbstyle.GridColumnStyles.Add(paiddatestyle);

tbstyle.GridColumnStyles.Add(memostyle);

dataGridPaidHistory.TableStyles.Add(tbstyle);

It does not work either, what's wrong with it?

Than's ahead.

Larry

Ken Tucker [MVP]
7/26/2004 12:49:34 PM
Hi,

I don't see where you set the tablestyles mapping name
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtablestyleclassmappingnametopic.asp

Ken
------------------
[quoted text, click to view]
Hi my friends,

I'm using a DataGrid Control to display a DataTable from Dataset. I can
display it in default format. I want to adjust the width of each column. I
went to properties of DataGrid control and set TableStyles and added
gridcolumnstyles in GridColumnStyles collection. But it doesn't work. Why.

I also tried to following code:
DataGridTableStyle tbstyle=new DataGridTableStyle();

DataGridTextBoxColumn paidtostyle=new DataGridTextBoxColumn();

paidtostyle.Width=400;

DataGridTextBoxColumn amountstyle=new DataGridTextBoxColumn();

amountstyle.Width=150;

DataGridTextBoxColumn paiddatestyle=new DataGridTextBoxColumn();

paiddatestyle.Width=100;

DataGridTextBoxColumn memostyle=new DataGridTextBoxColumn();

memostyle.Width=100;


tbstyle.GridColumnStyles.Add(paidtostyle);

tbstyle.GridColumnStyles.Add(amountstyle);

tbstyle.GridColumnStyles.Add(paiddatestyle);

tbstyle.GridColumnStyles.Add(memostyle);

dataGridPaidHistory.TableStyles.Add(tbstyle);

It does not work either, what's wrong with it?

Than's ahead.

Larry


Larry
7/26/2004 2:58:26 PM
Hello Ken,

Thank you very much for your help. I have got it.
DataGridTableStyle tbstyle=new DataGridTableStyle();

tbstyle.MappingName=myDataSet.Tables["PaidHIstory"].ToString();



Larry


ClayB [Syncfusion]
8/2/2004 7:24:11 AM
Try also setting ths MappingName of the tablestyle to be the DataTable name
before you add it to the grid's TablesStyles..

tbstyle.MappingName =
((DataTable)dataGridPaidHistory.DataSource).TableName;

=============================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools


[quoted text, click to view]

AddThis Social Bookmark Button