setting individual row heights in data grid

I have read and successfully tried the reflection based methodology to set the row heights in a data grid. However, when one uses a class derived from DataGrid reflection can't get to the private objects in the base class anymore as inheritance only propagates non-private items and hence property "DataGridRows" or method "get_DataGridRows" is not accessible through reflection anymore from the derived class. Has anyone seen a method that works even in a derived class?

4 Replies

JH Jurg Hinderling June 1, 2004 09:47 PM UTC

Getting and setting row heights is actually quite easy and will work for base and derived classesm no need to use reflection: Get: the rowheight of a grid row can always be determined from the GetCellBounds(row,col).Height property. Set: raise MouseDown and MouseUp events with MouseEventArgs set to same values as if one manually resized a column by clicking in the row resize area. Works perfectly.


JH Jurg Hinderling June 1, 2004 09:59 PM UTC

Gee, I am talking to myself :-) of course the approach I described without using reflection works only for derived classes as OnMouseUp and OnMouseDown are protected DatatGrid methods. Sorry for the confusion.


MA Manish June 11, 2004 01:03 PM UTC

I have the same porblem with the derived grid class. if your method does not require to use reflection and "get_DatagridRows" method. wonderful. Could you send me little code snippet. if you have. I did not quite understand the set : thing. thanks > Getting and setting row heights is actually quite easy and will work for base and derived classesm no need to use reflection: > > Get: the rowheight of a grid row can always be determined from the GetCellBounds(row,col).Height property. > > Set: raise MouseDown and MouseUp events with MouseEventArgs set to same values as if one manually resized a column by clicking in the row resize area. Works perfectly.


MA Manish June 11, 2004 01:22 PM UTC

I have used following code in autoresize method instead of relfection, but it does not seem to work. Dim i As Integer While i < numRows 'get the current height of he pearicular cell. size = g.MeasureString(dgEdit(i, 1).ToString(), dgEdit.Font, 400, sf) Dim h As Integer = Convert.ToInt32(size.Height) h = h + 10 Dim cellRect As Rectangle cellRect = dgEdit.GetCellBounds(i, 1) cellRect.Height = h i += 1 End While thanks. any idea. Manish > I have the same porblem with the derived grid class. if your method does not require to use reflection and "get_DatagridRows" method. wonderful. > > Could you send me little code snippet. if you have. I did not quite understand the set : thing. > > thanks > > > > > Getting and setting row heights is actually quite easy and will work for base and derived classesm no need to use reflection: > > > > Get: the rowheight of a grid row can always be determined from the GetCellBounds(row,col).Height property. > > > > Set: raise MouseDown and MouseUp events with MouseEventArgs set to same values as if one manually resized a column by clicking in the row resize area. Works perfectly. >

Loader.
Up arrow icon