Custom DataGridViewTextBoxCell refreshing...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin

    #1

    Custom DataGridViewTextBoxCell refreshing...

    I've created a custom class that inherits from the
    DataGridViewTex tBoxColumn and DataGridViewTex tBoxCell. The cell is
    databound to a text field that contains the path to a JPG image. The
    JPG image is displayed in the cell if the picture is present on the
    harddrive using Protected Overloads Overrides Sub Paint.

    The problem is that the image is only displayed in the cell when the
    cell receives the focus.

    How can I get it to paint the picture in each visible row without the
    row receiving focus first?
  • ClayB

    #2
    Re: Custom DataGridViewTex tBoxCell refreshing...

    Here is a custom cell class that worked ok for me to show a 10x10
    bitmap in a particular column in each row. Do the bitmaps you use fit
    into the cell?

    Public Class MyTextBoxCell
    Inherits DataGridViewTex tBoxCell

    Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal
    clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex
    As Integer, ByVal cellState As DataGridViewEle mentStates, ByVal value
    As Object, ByVal formattedValue As Object, ByVal errorText As String,
    ByVal cellStyle As DataGridViewCel lStyle, ByVal advancedBorderS tyle As
    DataGridViewAdv ancedBorderStyl e, ByVal paintParts As
    DataGridViewPai ntParts)
    MyBase.Paint(gr aphics, clipBounds, cellBounds, rowIndex,
    cellState, value, formattedValue, errorText, cellStyle,
    advancedBorderS tyle, paintParts)
    Dim pt As Point = cellBounds.Loca tion
    pt.Offset(2, 2)
    graphics.DrawIm age(Bitmap.From File("Bitmap1.b mp"), pt)
    End Sub 'Paint
    End Class 'MyTextBoxCell

    =============== =
    Clay Burch
    Syncfusion, Inc.

    Comment

    • Kevin

      #3
      Re: Custom DataGridViewTex tBoxCell refreshing...

      I was using a Property called Image that would retrieve the image from
      the file and for some reason the rowvalue wasn't being passed to it. I
      got rid of it altogether and retrieve the image in the Paint sub.

      I put the image into a picturebox the size I need the image to be and
      then I pass the picturebox image. Thanks for your reply. You made me
      rethink my code a little bit. Here's what I'm using:


      Protected Overloads Overrides Sub Paint(ByVal graphics As Graphics,
      ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal
      rowIndex As Integer, ByVal cellState As DataGridViewEle mentStates,
      ByVal value As Object, ByVal formattedValue As Object, ByVal errorText
      As String, ByVal cellStyle As DataGridViewCel lStyle, ByVal
      advancedBorderS tyle As DataGridViewAdv ancedBorderStyl e, ByVal
      paintParts As DataGridViewPai ntParts)
      MyBase.Paint(gr aphics, clipBounds, cellBounds, rowIndex,
      cellState, value, formattedValue, errorText, cellStyle,
      advancedBorderS tyle, paintParts)

      MyBase.Paint(gr aphics, clipBounds, cellBounds, rowIndex,
      cellState, value, formattedValue, _
      errorText, cellStyle, advancedBorderS tyle, paintParts)
      Dim pt As Point = cellBounds.Loca tion

      Try
      Dim OriginalImage As Image =
      Image.FromFile( My.Settings.Ima gePath + "\" + value)
      Dim SmallerImage As New Bitmap(Original Image,
      PictureBox1.Wid th, PictureBox1.Hei ght)
      PictureBox1.Ima ge = SmallerImage
      graphics.DrawIm age(PictureBox1 .Image, cellBounds.Loca tion)
      Catch
      'do nothing
      End Try
      End Sub




      On 11 Feb 2007 01:12:43 -0800, "ClayB" <clayb@syncfusi on.comwrote:
      >Here is a custom cell class that worked ok for me to show a 10x10
      >bitmap in a particular column in each row. Do the bitmaps you use fit
      >into the cell?
      >
      >Public Class MyTextBoxCell
      Inherits DataGridViewTex tBoxCell
      >
      Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal
      >clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex
      >As Integer, ByVal cellState As DataGridViewEle mentStates, ByVal value
      >As Object, ByVal formattedValue As Object, ByVal errorText As String,
      >ByVal cellStyle As DataGridViewCel lStyle, ByVal advancedBorderS tyle As
      >DataGridViewAd vancedBorderSty le, ByVal paintParts As
      >DataGridViewPa intParts)
      MyBase.Paint(gr aphics, clipBounds, cellBounds, rowIndex,
      >cellState, value, formattedValue, errorText, cellStyle,
      >advancedBorder Style, paintParts)
      Dim pt As Point = cellBounds.Loca tion
      pt.Offset(2, 2)
      graphics.DrawIm age(Bitmap.From File("Bitmap1.b mp"), pt)
      End Sub 'Paint
      >End Class 'MyTextBoxCell
      >
      >============== ==
      >Clay Burch
      >Syncfusion, Inc.

      Comment

      Working...