Original place: http://www.syncfusion.com/faq/winforms/faq_c44c.asp#q874q1. How do I use the program to set the rowheight in the DataGrid (Original http://www.syncfusion.com/faq/winforms/faq_c44c.asp#q1075q)
You can access the internal ROW object of DataGrid, which can be accessed by mapping. This method is mentioned on a private exchange of Matthew Benedict. This project file containing the VB and C # indicates the implementation of this method. Example provides a class that creates a RowHeight object via DataGrid. After you create this object, you can use this object's indexer to set or extract the height. 2. My DataGrid automatically sets a suggested solution for RowHeightSmatthew benedictt: Set the line high by mapping the DataGriDrows collection of the map.
Public void autosizegrid ()
{
// Work. This section of this DataGrid must be bound to DataTable
INT NumRows = (DataTable) Gridtasks.DataSource .Rows.count;
Graphics g = graphics.fromhwnd (gridtasks.handle);
StringFormat sf = new stringFormat (StringFormat.GenericTyPographic);
Sizef size;
// Du DataGridRows [] is not directly exposed because DataGrid
// We need to use the mapping mechanism .. The following GET_DATAGRIDROWS method returns the collection of rows we need and projected into System.Array
MethodInfo Mi = Gridtasks.gettype (). GetMethod ("get_datagridrows",
BindingFlags.Flattenhirarchy | BindingFlags.Ignorecase | BindingFlags.instance
| Bindingflags.nonpublic | bindingflags.public | bindingflags.static;
System.Array DGRA = (System.Array) MI.Invoke (Gridtasks, Null);
/ / Convert to ArrayList, a more easily handled, append to the new row we stripped.
ArrayList DataGridrows = new arraylist ();
Foreach (Object DGRR in DGRA)
{
IF (DGRR.TOString (). Endswith ("DataGridRelationshiprow") == True)
DataGridrows.Add (DGR);
}
// All lines in loop mesh
For (int I = 0; i { / / Here we speak the width setting to 400, this size will contain the height required Size = g.measureString (Gridtasks [i, 1] .tostring (), Gridtasks.Font, 400, sf); INT H = Convert.Toint32 (size.height); // Extra grid line space H = H 8; / / Now we will set out the row that has been set to the desired height attribute from the DataGridrows [] array. PropertyInfo Pi = DataGridrows [i] .gettype (). GetProperty ("height"); pi.setValue (DataGridrows [i], h, null; // i Have Read Here That After You Set The Height in this Manner That you shop // Call The DataGrid Invalidate () Method, But I Haven't Seen Any Prob with Not Calling It .. } g.dispose (); } 3. How to prevent one column from sorting in DataGrid Deritable DataGrid and overwrite onMousedowm. Rewrite HitText, if you click on the list of unwanted sorting, do not call the process of processing events. Below is sorting all columns except the second column [C #] // derived class Public Class MyDataGrid: DataGrid { Protected Override Void OnMouseDown (MouseEventArgs E) { Point Pt = New Point (E.x, E.Y); DataGrid.hittestinfo hti = this.hittest (PT); IF (hti.type == hittesttype.columnhead && hti.column == 1) { // Don't Sort COL 1 Return; // don't call Baseclass } Base.onmousedown (e); } } [Vb.net] 'Derived Class Public class mydatagrid Inherits DataGrid Protected Overrides Sub onmousedown (Byval e as system.windows.Forms.MouseEventArgs) DIM PT As New Point (E.x, E.Y) DIM HTI As DataGrid.hittestinfo = Me.hittest (Pt) If hti.type = hittesttype.columnheader andalso hti.column = 1 THEN 'Don't Sort COL 1 Return 'don't call Baseclass END IF Mybase.onmousedown (e) End Sub 'OnMouseDown End class' MyDataGrid 4. How to program a line code show as below [C #] // SELECT ROW 1 this.DataGrid1.select (1); [Vb.net] 'SELECT ROW 1 Me.DataGrid1.select (1) 5.