DataGridTextBoxColumn.GetPreferredHeight Method (Graphics, Object)

 
Use BaseTrue

Gets the height to be used in for automatically resizing columns.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

protected internal override int GetPreferredHeight(
	Graphics g,
	object value
)

Parameters

g
Type: System.Drawing.Graphics

A Graphics object used to draw shapes on the screen.

value
Type: System.Object

The value to draw.

Return Value

Type: System.Int32

The height the cells automatically resize to.

The following example uses the GetPreferredHeight to return the height a column is automatically resized to.

public class Form1: Form
{
 protected DataGrid dataGrid1;

private void GetPreferredHeight(){
   Graphics g;
   g = this.CreateGraphics();
   int gridPreferredHeight;
   MyGridColumn myTextColumn;
    // Assuming column 1 of a DataGrid control is a 
    // DataGridTextBoxColumn.
   myTextColumn = (MyGridColumn)
   dataGrid1.TableStyles[0].GridColumnStyles[1];
   string myVal;
   myVal = "A long string value";
   gridPreferredHeight= myTextColumn.GetPrefHeight(g, myVal);
   Console.WriteLine(gridPreferredHeight);
   }
}

public class MyGridColumn:DataGridTextBoxColumn{
   public int GetPrefHeight(Graphics g, string val){
      return this.GetPreferredHeight(g, val);
   }
}

.NET Framework
Available since 1.1
Return to top
Show: