Column Width and ExpandAllGroups

Hi,

I am trying to fix up the width of columns. My columns are being generated at runtime. Hence, on page load if I do grid.tabledescriptor.columns[0].width=100
it gives me a null reference exception. What is another way of doing it?

Also, I have set the ExpandAllGroups on the page load but it doesnt seem to work. I am using the latest version for Syncfusion (6.402.0.15).

Please help.


3 Replies

SS Saurabh Srivastava December 13, 2008 11:36 AM UTC


Hi,

I am able to refernce columns now. I was not binding at runtime and that was the reason why it was not accessible. The ExpandAllGroups() now works fine. But I am still not able to alter the width of the columns. I am applying a custom CSS on the grid. Is that the reason for it?





RS Rajarajeswari S Syncfusion Team December 15, 2008 06:21 AM UTC

Hi Saurabh,

I am afraid that I am not able to reproduce the issue, that you have mentioned here. Applying Custom CSS doesn’t affect of setting column width. Please refer the below sample where I have followed the below things:

1. Created Grid, and applied custom CSS.
2. Creating a new column dynamically.
3. Setting width for the dynamically created column.
4. The width is applied to the column properly.

Please refer the below code snippet which illustrates this:

protected void Button1_Click(object sender, EventArgs e)
{
this.GridGroupingControl1.TableDescriptor.Columns.Add("NewColumn");
GridColumnDescriptor gcd = this.GridGroupingControl1.TableDescriptor.GetColumnDescriptor("NewColumn");
gcd.Width = 300;
}

Please refer the sample from the below link, which illustrates the above:

http://www.syncfusion.com/support/user/uploads/Sample_f8581c1.zip

Please let me know if you have any other concerns.

Regards,
Raji




SS Saurabh Srivastava January 6, 2009 04:55 AM UTC

Hi,

I tried all possible combinations to set the column width, but none seems to work.

I am creating the columns dynamically by a stored procedure.

Following are the methods are I tried:

//METHOD 1
this.GridGroupingControl1.TableDescriptor.Columns[1].MaxLength = 10;

//METHOD 2
for (int i = 0; i < this.GridGroupingControl1.TableDescriptor.Columns.Count; i++) this.GridGroupingControl1.TableDescriptor.Columns[i].Width = 20;

//METHOD 3
this.GridGroupingControl1.TableDescriptor.Columns[1].MaxLength = 10; this.GridGroupingControl1.TableOptions.ColumnsMaxLengthStrategy = GridColumnsMaxLengthStrategy.MaxLengthSummary;

//METHOD 4
this.GridGroupingControl1.TableOptions.DefaultColumnWidth = 10;

//METHOD 5
GridColumnDescriptor gcd = this.GridGroupingControl1.TableDescriptor.GetColumnDescriptor("myColumn");
gcd.Width = 20;

This is my design time defn of Gridgrouping control:
ShowGroupDropArea="False" BorderCollapse="Separate" OnQueryCellStyleInfo="cControl_QueryCellStyleInfo" OnQueryCoveredRange="cControl_QueryCoveredRange" EnablePostbacks="false" TableDescriptor-AllowEdit="false" TableOptions-AllowDragColumns="false" Width="400"
TableOptions-AllowSortColumns="false" ReadOnly="true" TableDescriptor-AllowColumnResize="false">


Please advise.

Thanks




Loader.
Up arrow icon