B
bismarkjoe
Hello,
I am trying to set the widths on the columns of a DataGrid component,
and I'm not sure if I'm doing it correctly. My code is below:
//load some inital data
table = db.GetDataTable( "SELECT 'Task' AS 'Type', title AS 'Title',
IFNULL(u.name, 'Nobody') AS 'Assigned To' FROM tasks t LEFT JOIN
users u ON t.assigned_to=u.user_id LIMIT 0, 30" );
grid.ReadOnly = true;
//add the table style
DataGridTableStyle TableStyle = new DataGridTableStyle(true);
grid.TableStyles.Add( TableStyle );
//set the datasource view
grid.DataSource = table.DefaultView;
int[] widths = { 35, 175, 70 };
for( int i = 0; i < table.Columns.Count; i++ )
{
if( i < TableStyle.GridColumnStyles.Count )
TableStyle.GridColumnStyles.Width = widths;
}
This seems to work for me initially. However it seems like a lot of
code to just set the widths of columns, so I was wondering if there
is an easier/better way?
Also, on a side note if I give the table a name (i.e. table.TableName
="Tasks" before I attempt to resize the columns with the code
above. Then it will not resize the columns at all (The
TableyStyle.GridColumnStyles.Count is 0)... why is this?
Thanks in advance.. this problem has been frustrating me for a while.
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
I am trying to set the widths on the columns of a DataGrid component,
and I'm not sure if I'm doing it correctly. My code is below:
//load some inital data
table = db.GetDataTable( "SELECT 'Task' AS 'Type', title AS 'Title',
IFNULL(u.name, 'Nobody') AS 'Assigned To' FROM tasks t LEFT JOIN
users u ON t.assigned_to=u.user_id LIMIT 0, 30" );
grid.ReadOnly = true;
//add the table style
DataGridTableStyle TableStyle = new DataGridTableStyle(true);
grid.TableStyles.Add( TableStyle );
//set the datasource view
grid.DataSource = table.DefaultView;
int[] widths = { 35, 175, 70 };
for( int i = 0; i < table.Columns.Count; i++ )
{
if( i < TableStyle.GridColumnStyles.Count )
TableStyle.GridColumnStyles.Width = widths;
}
This seems to work for me initially. However it seems like a lot of
code to just set the widths of columns, so I was wondering if there
is an easier/better way?
Also, on a side note if I give the table a name (i.e. table.TableName
="Tasks" before I attempt to resize the columns with the code
above. Then it will not resize the columns at all (The
TableyStyle.GridColumnStyles.Count is 0)... why is this?
Thanks in advance.. this problem has been frustrating me for a while.
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*