How to make the gray area of the grid white?

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

Guest

I'm developing an application for Pocket PC in VB .NET. My grid can contain
up to 10 rows, but my table has only 2 and I see the dark gray area. Is there
a way to change the color of it? 'DataGrid1.BackgroundColor' works for a
Windows Application, but not Smart Device Application...
 
I haven't tested the code below, but it looks pretty good. I got this code
from the following translator. I modified it slightly.
http://www.kamalpatel.net/ConvertCSharp2VB.aspx

Imports System.Reflection

Public Shared Sub SetGridBackColor(ByVal dg As DataGrid, ByVal clr As
Color)
Dim oRenderer As Object = Type.GetType(DataGrid).GetField("m_renderer",
BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(dg)
oRenderer.GetType().GetField("m_brushEmptyBack", BindingFlags.NonPublic Or
BindingFlags.Instance).SetValue(oRenderer, New SolidBrush(clr))
End Sub
 
I'm getting this error:
"'DataGrid' is a type and cannot be used as an expression",
which is pointing to "Type.GetType(DataGrid)...."
 
The following code works.

Public Shared Sub SetGridBackColor(ByVal dg As DataGrid, ByVal clr As Color)

Dim oRenderer As Object = dg.GetType().GetField("m_renderer",
BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(dg)

oRenderer.GetType().GetField("m_brushEmptyBack", BindingFlags.NonPublic Or
BindingFlags.Instance).SetValue(oRenderer, New SolidBrush(clr))

dg.Invalidate()

End Sub
 
Just as FYI, if you post to the official Compact Framework newsgroup
(microsoft.public.dotnet.framework.compactframework) you'll usually get a
quicker reply.
 
Back
Top