We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Stack overflow exception using QueryColWidth

I''m using the following code in the QueryColWidth event of a data bound grid. if (e.Index == 2) { int width = this.gridDocuments.Model.ColCount <= 0 ? 0 : (this.gridDocuments.Model.ColWidths.GetTotal(0, this.gridDocuments.Model.ColCount-1)-this.gridDocuments.Model.Cols.Size[2]); e.Size = this.gridDocuments.ClientRectangle.Width-width; e.Handled = true; } The intent (based upon postings in this forum) is to resize the second column based on the widths of the other column. The example this is borrowed from was intended to resize the last column. I want to resize a column in the middle of the other columns. The problem is that this results in a stack overflow exception in the grid. If I change the code to use the last column in the grid it works fine.

3 Replies

AD Administrator Syncfusion Team October 13, 2004 01:28 PM UTC

You cannot try to reference this.gridDocuments.Model.Cols.Size[2]); from within the code when e.Index = 2. The reason is that trying to retrieve this.gridDocuments.Model.Cols.Size[2]) trigeers a call to QueryColWidth with e.Index = 2. So, you get into a recursive call situation which leads to teh stack overflow. So, instead of int width = this.gridDocuments.Model.ColCount <= 0 ? 0 : (this.gridDocuments.Model.ColWidths.GetTotal(0, this.gridDocuments.Model.ColCount-1)-this.gridDocuments.Model.Cols.Size[2]); try
if(e.Index == 2)
{
	int width = this.gridDocuments.Model.ColWidths.GetTotal(0, 1);
	if(this.gridDocuments.Model.ColCount > 2)
		width += this.gridDocuments.Model.ColWidths.GetTotal(3,this.gridDocuments.Model.ColCount);
	e.Size = this.gridDocuments.ClientRectangle.Width - width;
	e.Handled = true;
}


AD Administrator Syncfusion Team October 13, 2004 03:28 PM UTC

Thank you, that worked. Not sure what I was thinking there.


AD Administrator Syncfusion Team October 13, 2004 03:59 PM UTC

Related question: This solution works, but the column headings don''t redraw very well once you resize a particular column. Is there something I can do to fix that?

Loader.
Live Chat Icon For mobile
Up arrow icon