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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

optimal size on rowheader column.

Thread ID:

Created:

Updated:

Platform:

Replies:

8995 Dec 2,2003 10:16 AM UTC Dec 5,2003 12:44 PM UTC WinForms 6
loading
Tags: GridControl
Markus Kraft
Asked On December 2, 2003 10:16 AM UTC

Hi, after i build my gridboundcolumncollection the following codesnippet will formatting the rowheader column. The autosize mechanism will not work correct and doubleclick on columnboarder will not set the optimal size. More than 10000 entries are after a copying process in the table. Why doesn't this work at RowHeader-Column? greetings markus codesnippet: #region 3.2 RowNumber in Column[0] GridStyleInfo gsiStyleOfRow = m_ValueGrid.Model.BaseStylesMap["Row Header"].StyleInfo; gsiStyleOfRow.CellType = "Header"; gsiStyleOfRow.Font.Bold = false; gsiStyleOfRow.WrapText = false; gsiStyleOfRow.AutoSize = true; gsiStyleOfRow.HorizontalAlignment = GridHorizontalAlignment.Center; m_ValueGrid.Model.Options.NumberedRowHeaders = true; #endregion

Administrator [Syncfusion]
Replied On December 2, 2003 11:03 AM UTC

style.AutoSize only works for key board input. It allows for adjusting cells as your user types. If you want to programatically autosize things, then you would explicitly call grid.Model.RowHeights.ResizeToFit and grid.Model.ColWidths.ResizeToFit. Doubling clicking a header cell border does not set the optimal size. Instead it sets the default size. So, if you user has been changing his colwidths, he can double click the border to reset things back to the default. The code tries to auto If you want the doubleclick to behave differently, you can handle this event.
private void gridControl1_ResizingColumns(object sender, GridResizingColumnsEventArgs e)
{
	if(e.Reason.Equals(GridResizeCellsReason.DoubleClick))
	{
		GridRangeInfo range = e.Columns; 
	this.gridControl1.Model.ColWidths.ResizeToFit(range, 
                			GridResizeToFitOptions.IncludeHeaders);
		e.Cancel = true;
	}
}
If you have a many rows, then ResizeToFit will visit each row to compute the optimal size, and this may be time consuming. So, you may want to restrict the resizing to the visible grid (grid.ViewLayout.VisibleCellsRange) or in some other manner.

Markus Kraft
Replied On December 4, 2003 03:27 AM UTC

Many thanks for the detailed answer. greetings markus

Markus Kraft
Replied On December 4, 2003 04:11 AM UTC

Hi Clay, the methode works up to 4-digit values correct, but on 5-digit values only the first 4 digits will be visible after "ResizeToFit". How can i display more then 4-digit values in the "RowHeader-Column" ? The ResizingColumns Eventhandler in my solution is the same as you described but the handler works only up to 4-digits correct. greetings markus

Administrator [Syncfusion]
Replied On December 4, 2003 07:27 AM UTC

If you are using the default row numbers, these numbers really are not the Style.Text properties of the header cell styles. Instead, the style.Text properties for these header cells are actually empty. And the only sizing that is done is the minimum size for an empty column. (Clicking your header border does not make the column more narrow if your only have 9 columns). If you actually want to size this header column when it is using the default numbers, you can do it smartly, knowing that the last row will always be the widest. In this manner, if you have 100000 rows, you can size things by only looking at 1 cell instead of 100000 cells. Here is a modified event handler that attempts this. It explcitly sets teh value in teh last header cell so its style.Text property is not empty, and can be resized.
private void gridControl1_ResizingColumns(object sender, GridResizingColumnsEventArgs e)
{
	if(e.Reason.Equals(GridResizeCellsReason.DoubleClick))
	{
		GridRangeInfo range = e.Columns;
		if(range.Left == 0)
		{
			range = GridRangeInfo.Cell(this.gridControl1.RowCount, 0);
			this.gridControl1[this.gridControl1.RowCount, 0].Text = 
				this.gridControl1.RowCount.ToString();
			this.gridControl1.Model.ColWidths.ResizeToFit(range, 
				GridResizeToFitOptions.IncludeHeaders);
			if(range.Right > 0)
			{
				range = GridRangeInfo.Cols(1, range.Right);
			}
			else
			{
				e.Cancel = true;
				return;
			}
		}
		this.gridControl1.Model.ColWidths.ResizeToFit(range, 
			GridResizeToFitOptions.IncludeHeaders);
		e.Cancel = true;
	}
}

Markus Kraft
Replied On December 5, 2003 11:18 AM UTC

Hi Clay, i cannot write the columnnumber in the specific cell via this methode (i use a databoundgrid but the mechanism is the same): m_ValueGrid[m_ValueGrid.Model.RowCount, 0].Text = m_ValueGrid.Model.RowCount.ToString(); After this action i debug the text property and the value is "". Is the headerrow-column writeprotected?

Administrator [Syncfusion]
Replied On December 5, 2003 12:44 PM UTC

If you want to have row headers in a GridDataBoundGrid, then you would have to handle grid.Model.QueryCellInfo or grid.PrepareViewStyleInfo, and set e.Style.text based on the e.RowIndex value when e.ColIndex = 0. In a GridDataBoundGrid, the grid stores no information on a row or cell basis. So, if you want this information to be available, you have to dynamically provide it through one of these events. I think if you handle QueryCellInfo, providing the row header values there, the above code would work without you setting this.gridControl1[this.gridControl1.RowCount, 0].Text = this.gridControl1.RowCount.ToString(); The reason is the header cells would no longer be empty. Their values would be the values provided in QueryCellInfo.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;