DataGrid - Setting Row Height in Derived DataGrids

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a class that inherits from DataGrid. I can set the rowheights in a
DataGrid by tappig into the "get_Datagridrows" method. However, this does
not work for classes that inherit from DataGrid. Anyone know how to do this
on derived classes? I find it apalling that Microsoft provided a DataGrid
that is so inflexible!
 
Hi,

I converted the grid in the article dragging and dropping datagrid
columns to vb.net. Noticed get_Datagridsrows method doesnt work until the
grid had drawn itself.


Ken
-----------------
I have a class that inherits from DataGrid. I can set the rowheights in a
DataGrid by tappig into the "get_Datagridrows" method. However, this does
not work for classes that inherit from DataGrid. Anyone know how to do this
on derived classes? I find it apalling that Microsoft provided a DataGrid
that is so inflexible!
 
Your code works find if you have just a datagrid. However, when you have a
class that inherits datagrid, mi is returned as nothing. I even tried using
mybase.GetType instead of me.GetType inside of the class.
 
Thanks to "Imran Koradia" :

Here's code that works to get and set rowheights in derived DataGrids. Note
the function to get the rowobjects and get/set property is all within the
derived DataGrid Class called mydatagrid. The RowObject array of rows is
updated by calling get_RowObjects whenever the datasource changes or a row is
changed with the mouse:

Public Class mydatagrid
Private RowObjects as Arraylist = new Arraylist

'Call this whenever datasource changes or row height changed by mouse
Private Function get_RowObjects() As ArrayList
Dim rows As ArrayList = New ArrayList
Dim a As Type = Me.GetType
Dim b As Type = a.BaseType
Dim mi As MethodInfo = b.GetMethod("get_DataGridRows",
BindingFlags.FlattenHierarchy Or BindingFlags.IgnoreCase Or
BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or
BindingFlags.Static)
Dim dgra As System.Array = CType(mi.Invoke(Me, Nothing), System.Array)
Dim dgrr As Object
For Each dgrr In dgra
If dgrr.ToString().EndsWith("DataGridRelationshipRow") = True Then
rows.Add(dgrr)
End If
Next dgrr
Return rows
End Function 'get_RowHeights

'Use this Property to set or get rowheights
Public Property RowHeight(ByVal row As Integer) As Integer
Get
Try
Dim pi As PropertyInfo =
rowObjects(row).GetType().GetProperty("Height")
Return CInt(Fix(pi.GetValue(rowObjects(row), Nothing)))
Catch
Throw New ArgumentException("invalid row index")
End Try
End Get
Set(ByVal Value As Integer)
Try
Dim pi As PropertyInfo =
rowObjects(row).GetType().GetProperty("Height")
pi.SetValue(rowObjects(row), Value, Nothing)
Catch
Throw New ArgumentException("invalid row index")
End Try
End Set
End Property

Thanks a lot for helping me.
 
Actually - anyone have any idea how I can get the vertical scrolling
for this working correctly?

I'm actually using a wrapped-text derived Column, followed by the
syncfusion method for setting rowheights automatically. However, the
vertical scrollbar doesn't appear corrently (if the wrap-text column
is 2 lines, then you need to add an additional line into the datatable
before the vert scrollbar appears, and then it will let you scroll
down (and not be able to view the last record)

It appears that the scrollbar doesn't take account of
larger-than-normal rowheights, if they're set by reflection.

Argh!

B.
 
I share your thoughts regarding the Microsoft DataGrid..ARGH! It is really
not suited for much customization although they claim it is. I have even had
trouble getting it to show data in the column when a column is scrolled back
on to the screen. Also, it doesn't sort bound arraylists. I've given up on
it and am currently working on my own...I don't like paying 200 to 300 bucks
for a third party control.

You'd think Microsoft could produce a better control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top