PC Review


Reply
Thread Tools Rate Thread

DataGrid - Setting Row Height in Derived DataGrids

 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      23rd Oct 2004
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
 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      24th Oct 2004
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" <(E-Mail Removed)> wrote in message
news:054949F8-D685-4BB6-A9FF-(E-Mail Removed)...
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


 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      24th Oct 2004
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" <(E-Mail Removed)> wrote in message
> news:054949F8-D685-4BB6-A9FF-(E-Mail Removed)...
> 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
>
>
>

 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      24th Oct 2004
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" <(E-Mail Removed)> wrote in message
> news:054949F8-D685-4BB6-A9FF-(E-Mail Removed)...
> 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
>
>
>

 
Reply With Quote
 
Barry Zubel
Guest
Posts: n/a
 
      17th Nov 2004
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 <(E-Mail Removed)> wrote in message news:<372C5617-C9B9-423C-9233-(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> > news:054949F8-D685-4BB6-A9FF-(E-Mail Removed)...
> > 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
> >
> >
> >

 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      18th Nov 2004
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 <(E-Mail Removed)> wrote in message news:<372C5617-C9B9-423C-9233-(E-Mail Removed)>...
> > 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" <(E-Mail Removed)> wrote in message
> > > news:054949F8-D685-4BB6-A9FF-(E-Mail Removed)...
> > > 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
> > >
> > >
> > >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting datagrid height RateTheBuilder Microsoft C# .NET 1 19th Dec 2006 05:45 AM
Setting the Row Height in DataGrid =?Utf-8?B?UmFtbmFkaA==?= Microsoft Dot NET Framework 0 28th Mar 2005 04:33 PM
Setting the Column Width in DataGrids =?Utf-8?B?Qm9iIEF2YWxsb25l?= Microsoft Dot NET Framework Forms 6 12th Nov 2004 08:16 PM
Custom control derived from DataGrid =?Utf-8?B?TWljaGFsIFJpemVr?= Microsoft Dot NET Compact Framework 4 5th Nov 2004 03:45 PM
Setting a DataGrid row height to fit the text Bruce Wolfe Microsoft C# .NET 0 6th Jan 2004 05:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:08 AM.