Nelviticus
Programmer
I have a DataGrid on my Windows form. I set its DataSource to a DataView of a table that has a variable number of columns.
I want to re-size the DataGrid columns so that they're wide enough to show the names of each column - by default they are a standard width, so any columns with long names will only show part of the name.
Is there a way to do this? I have not even been able to set the widths to arbitrary values, let alone calculated sizes. This is what I tried based on something I read here:
My columns are all either strings or boolean. This code did nothing at all - the columns remained at the default widths.
Any idea what I'm doing wrong?
Regards
Nelviticus
I want to re-size the DataGrid columns so that they're wide enough to show the names of each column - by default they are a standard width, so any columns with long names will only show part of the name.
Is there a way to do this? I have not even been able to set the widths to arbitrary values, let alone calculated sizes. This is what I tried based on something I read here:
Code:
DataGridTableStyle vStyle = new DataGridTableStyle();
foreach(DataColumn vColumn in dvMyView.Table.Columns)
{
if (vColumn.DataType.ToString().ToLower()=="system.string")
{
DataGridTextBoxColumn vColumnStyle = new DataGridTextBoxColumn();
vColumnStyle.Width = 15;
vStyle.GridColumnStyles.Add(vColumnStyle);
}
else
{
DataGridBoolColumn vColumnStyle = new DataGridBoolColumn();
vColumnStyle.Width = 25;
vStyle.GridColumnStyles.Add(vColumnStyle);
}
}
dgMyGrid.TableStyles.Add(vStyle);
dgMyGrid.DataSource = dvMyView;
My columns are all either strings or boolean. This code did nothing at all - the columns remained at the default widths.
Any idea what I'm doing wrong?
Regards
Nelviticus