Still trying to get rich text from my dataset into a datagrid. So far, my
strategy has been to derive a custom column style which owns a rich text
box:
Public Class RTColumn
Inherits DataGridColumnStyle
Dim WithEvents rtb As RichTextBox = New RichTextBox()
Dim PHeight As Integer = 0
Dim PSize As Size
Dim MHeight As Integer = 0
Dim ioMemoryStream As MemoryStream
Dim rtbg As Graphics
Dim mfMetaFile As Metafile
Dim ptrHDC As IntPtr
I want the rich text box with events, because I'd like to know the size of
the contents when the text is assigned to rtb:
Private Sub rtb_ContentsResized(ByVal sender As Object, ByVal e As
System.Windows.Forms.ContentsResizedEventArgs) Handles rtb.ContentsResized
If e.NewRectangle.Height > MHeight Then
MHeight = e.NewRectangle.Height
End If
If e.NewRectangle.Height > PHeight Then
PHeight = e.NewRectangle.Height
End If
PSize = e.NewRectangle.Size
End Sub
To draw the contents of the rtb, I create a metafile in the Paint override:
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
ByVal bounds As System.Drawing.Rectangle, ByVal [source] As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush,
ByVal alignToRight As Boolean)
Try
Dim rt As String = Me.GetColumnValueAtRow([source], rowNum)
g.FillRectangle(backBrush, bounds) 'this has the effect
of erasing the cell
If rt <> "" Then
rtb.Rtf = rt
ioMemoryStream = New MemoryStream()
' Get a graphics context from the RichTextBox
Dim rtbg As Graphics = rtb.CreateGraphics
' Get the device context from the graphics context
ptrHDC = rtbg.GetHdc()
' Create a new Enhanced Metafile from the device context
mfMetaFile = New Metafile(ioMemoryStream, ptrHDC)
' Release the device context
rtbg.ReleaseHdc(ptrHDC)
' Draw the metafile
g.DrawImage(mfMetaFile, bounds.X, bounds.Y, PSize.Width,
PSize.Height)
End If
Catch
MsgBox(Err.Description)
End Try
End Sub 'Paint
Not only does this fail to draw the rich text in the datagrid cell, but I
get a 'Cast from type 'DBNull' to type 'String' is not valid' error after
scrolling the grid to the last row.
I know about the dotnet.leadit.be/extendeddatagrid. It looks intruiging,
but I'd really rather understand what I'm doing, and not have to include
another dll with my project. If anyone can point out the error of my ways,
I'd very much appreciate it. 2 1162
Lisa,
To avoid the cast from dbnull to string error use
getcolumnvalueatrow.tostring
Dim rt As String = Me.GetColumnValueAtRow([source], rowNum).tostring
Here is a link on how print a rich text box contents. Maybe the
graphics code will help. http://msdn.microsoft.com/library/de...ichTextBox.asp
Ken
---------------------
"Lisa" <sp****@herplace.com> wrote in message
news:Cc********************@eatel.net... Still trying to get rich text from my dataset into a datagrid. So far, my strategy has been to derive a custom column style which owns a rich text box:
Public Class RTColumn Inherits DataGridColumnStyle
Dim WithEvents rtb As RichTextBox = New RichTextBox() Dim PHeight As Integer = 0 Dim PSize As Size Dim MHeight As Integer = 0 Dim ioMemoryStream As MemoryStream Dim rtbg As Graphics Dim mfMetaFile As Metafile Dim ptrHDC As IntPtr
I want the rich text box with events, because I'd like to know the size of the contents when the text is assigned to rtb:
Private Sub rtb_ContentsResized(ByVal sender As Object, ByVal e As System.Windows.Forms.ContentsResizedEventArgs) Handles rtb.ContentsResized If e.NewRectangle.Height > MHeight Then MHeight = e.NewRectangle.Height End If If e.NewRectangle.Height > PHeight Then PHeight = e.NewRectangle.Height End If PSize = e.NewRectangle.Size End Sub
To draw the contents of the rtb, I create a metafile in the Paint override: Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush, ByVal alignToRight As Boolean) Try Dim rt As String = Me.GetColumnValueAtRow([source], rowNum) g.FillRectangle(backBrush, bounds) 'this has the effect of erasing the cell If rt <> "" Then rtb.Rtf = rt ioMemoryStream = New MemoryStream() ' Get a graphics context from the RichTextBox Dim rtbg As Graphics = rtb.CreateGraphics ' Get the device context from the graphics context ptrHDC = rtbg.GetHdc() ' Create a new Enhanced Metafile from the device context mfMetaFile = New Metafile(ioMemoryStream, ptrHDC) ' Release the device context rtbg.ReleaseHdc(ptrHDC) ' Draw the metafile g.DrawImage(mfMetaFile, bounds.X, bounds.Y, PSize.Width, PSize.Height)
End If Catch MsgBox(Err.Description) End Try End Sub 'Paint
Not only does this fail to draw the rich text in the datagrid cell, but I get a 'Cast from type 'DBNull' to type 'String' is not valid' error after scrolling the grid to the last row.
I know about the dotnet.leadit.be/extendeddatagrid. It looks intruiging, but I'd really rather understand what I'm doing, and not have to include another dll with my project. If anyone can point out the error of my ways, I'd very much appreciate it.
Ken,
Thanks - the .tostring was a dumb error on my part. And thanks for the
reference: I'll look at it tonight.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ek****************@tk2msftngp13.phx.gbl... Lisa,
To avoid the cast from dbnull to string error use getcolumnvalueatrow.tostring
Dim rt As String = Me.GetColumnValueAtRow([source], rowNum).tostring
Here is a link on how print a rich text box contents. Maybe the graphics code will help. http://msdn.microsoft.com/library/de...ichTextBox.asp Ken ---------------------
"Lisa" <sp****@herplace.com> wrote in message news:Cc********************@eatel.net... Still trying to get rich text from my dataset into a datagrid. So far,
my strategy has been to derive a custom column style which owns a rich text box:
Public Class RTColumn Inherits DataGridColumnStyle
Dim WithEvents rtb As RichTextBox = New RichTextBox() Dim PHeight As Integer = 0 Dim PSize As Size Dim MHeight As Integer = 0 Dim ioMemoryStream As MemoryStream Dim rtbg As Graphics Dim mfMetaFile As Metafile Dim ptrHDC As IntPtr
I want the rich text box with events, because I'd like to know the size
of the contents when the text is assigned to rtb:
Private Sub rtb_ContentsResized(ByVal sender As Object, ByVal e As System.Windows.Forms.ContentsResizedEventArgs) Handles
rtb.ContentsResized If e.NewRectangle.Height > MHeight Then MHeight = e.NewRectangle.Height End If If e.NewRectangle.Height > PHeight Then PHeight = e.NewRectangle.Height End If PSize = e.NewRectangle.Size End Sub
To draw the contents of the rtb, I create a metafile in the Paint override: Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush, ByVal alignToRight As Boolean) Try Dim rt As String = Me.GetColumnValueAtRow([source], rowNum) g.FillRectangle(backBrush, bounds) 'this has the
effect of erasing the cell If rt <> "" Then rtb.Rtf = rt ioMemoryStream = New MemoryStream() ' Get a graphics context from the RichTextBox Dim rtbg As Graphics = rtb.CreateGraphics ' Get the device context from the graphics context ptrHDC = rtbg.GetHdc() ' Create a new Enhanced Metafile from the device context mfMetaFile = New Metafile(ioMemoryStream, ptrHDC) ' Release the device context rtbg.ReleaseHdc(ptrHDC) ' Draw the metafile g.DrawImage(mfMetaFile, bounds.X, bounds.Y, PSize.Width, PSize.Height)
End If Catch MsgBox(Err.Description) End Try End Sub 'Paint
Not only does this fail to draw the rich text in the datagrid cell, but
I get a 'Cast from type 'DBNull' to type 'String' is not valid' error
after scrolling the grid to the last row.
I know about the dotnet.leadit.be/extendeddatagrid. It looks
intruiging, but I'd really rather understand what I'm doing, and not have to include another dll with my project. If anyone can point out the error of my ways, I'd very much appreciate it.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems...
|
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that...
|
by: tshad |
last post by:
I am having trouble with links in my DataGrid.
I have Links all over my page set to smaller and they are consistant all
over the page in both Mozilla and IE, except for the DataGrid.
Here is a...
|
by: CSL |
last post by:
I am using the DataGrid in a Windows Application, how can
I adjust the widths of each column individually.
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |