469,140 Members | 1,225 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

DataGrid - Setting Row Height in Derived DataGrids

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!

--
Dennis in Houston
Nov 21 '05 #1
5 4526
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
-----------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
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!

--
Dennis in Houston
Nov 21 '05 #2
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.

"Ken Tucker [MVP]" wrote:
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
-----------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
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!

--
Dennis in Houston

Nov 21 '05 #3
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.

"Ken Tucker [MVP]" wrote:
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
-----------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
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!

--
Dennis in Houston

Nov 21 '05 #4
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.

Dennis <De****@discussions.microsoft.com> wrote in message news:<37**********************************@microso ft.com>...
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.

"Ken Tucker [MVP]" wrote:
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
-----------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
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!

--
Dennis in Houston

Nov 21 '05 #5
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.

"Barry Zubel" wrote:
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.

Dennis <De****@discussions.microsoft.com> wrote in message news:<37**********************************@microso ft.com>...
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.

"Ken Tucker [MVP]" wrote:
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
-----------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
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!

--
Dennis in Houston

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stephan Steiner | last post: by
3 posts views Thread by TT (Tom Tempelaere) | last post: by
2 posts views Thread by Sebastian | last post: by
9 posts views Thread by tshad | last post: by
13 posts views Thread by pmcguire | last post: by
2 posts views Thread by Brian Tkatch | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.