Hi Hajash,
if it is a web datagrid you can set it by
this.DataGrid1. Columns[x].ItemStyle.Widt h = xx;
If it is windows forms here is a sample:
To set a column width, your datagrid must be using a non-null
DataGridTableSt yle. Once this is in place, you can set the column width
by first getting the tablestyle and then using that object to obtain a
column style with which you can set the width. Here are some code
snippets showing how you might do this.
//.... make sure your DataGrid is using a tablestyle
dataGrid1.DataS ource = _dataSet.Tables["customers"];
DataGridTableSt yle dgts = new DataGridTableSt yle();
dgts.MappingNam e = "customers" ;
dataGrid1.Table Styles.Add(dgts );
//method to set a column with by colnumber
public void SetColWidth(Dat aGridTableStyle tableStyle, int colNum, int
width)
{
try
{
tableStyle.Grid ColumnStyles[colNum].Width = width;
tableStyle.Data Grid.Refresh();
}
catch{} //empty catch .. do nothing
}
// here is how you might call this method
private void button1_Click(o bject sender, System.EventArg s e)
{
DataGridTableSt yle tableStyle = dataGrid1.Table Styles["customers"];
SetColWidth(tab leStyle, 1, 200);
}
Santiago Corredoira
www.syltek.com
Hajash wrote:
hi all,
how do i set the width of a column in a datagrid.Please help.Thanks in
advance.
regards,
hajash