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)

public protected:
virtual int GetPreferredHeight(
	Graphics^ g,
	Object^ value
) override

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 ref class MyGridColumn: public DataGridTextBoxColumn
{
public:
   int GetPrefHeight( Graphics^ g, String^ val )
   {
      return this->GetPreferredHeight( g, val );
   }

};

public ref class Form1: public 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 = dynamic_cast<MyGridColumn^>(dataGrid1->TableStyles[ 0 ]->GridColumnStyles[ 1 ]);
      String^ myVal;
      myVal = "A long string value";
      gridPreferredHeight = myTextColumn->GetPrefHeight( g, myVal );
      Console::WriteLine( gridPreferredHeight );
   }

};

.NET Framework
Available since 1.1
Return to top
Show: